I have the following script, that loops every 60 seconds. All works fine, but after two or three hours the script stops. I have no idea why.
<?php
// The worker will execute every X seconds:
$seconds = 60;
// We work out the micro seconds ready to be used by the 'usleep' function.
$micro = $seconds * 1000000;
while(true){
try {
$url = 'URL';
$fields = array(
"hi"=> 1,
"world"=> 2,
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
$fields_string = rtrim($fields_string,'&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_exec($ch);
} catch (Exception $e) {
$myFile = "/usr/share/test/filephp.txt";
$fh = fopen($myFile, 'a') or die("Can't open file");
$stringData = "File updated at: " . time(). "\n";
fwrite($fh, $stringData);
fclose($fh);
}
// Now before we 'cycle' again, we'll sleep for a bit...
usleep($micro);
}
The PHP script is executed with this command:
sudo -u root php -f /usr/share/test/test.php &
Any ideas?
max_execution_timesetting. But why don't you just run it as a cron job instead of a continuous loop?