I am running PHP 5.2 on Fedora, and I continue to receive this warning after about 1000 iterations of my loop, which means the program has stopped working and needs to be restarted. I could set this to exit after 1000 iterations and restart via cron shortly afterwards, but this seems like a cowardly exit. The cycle follows; I must add that get_load()transforms the challenge file_get_contents().
while ($row = select_row($sql))
{
while (($load = get_load()) > 10)
{
echo "Going to sleep (load: ".$load.")\n";
sleep(60*3);
}
$id = $row['id'];
foreach ($sizes as $abbr=>$size)
{
if($row[$size] != "yes")
{
continue;
}
$filename = "/images/".$abbr."/".$id.".jpg";
$tmp_file = "/tmp/".$id.".jpg";
if ($size == "large")
{
$cmd = "convert -strip -interlace Plane ".$filename." ".$tmp_file;
}
else
{
$cmd = "convert -strip ".$filename." ".$tmp_file;
}
$convert = popen($cmd." 2>&1", "r");
if (is_resource($convert))
{
echo fgets($convert);
if(pclose($convert) == 0)
{
}
unlink($tmp_file);
}
}
Edit: after reading the first two answers, I realized that, taking out the file upload code, which is not related to my problem, I took out my operator pclose(). Paste pclose()as shown in my code.
Further editing: Added get_load()on request
function get_load()
{
$load = explode(" ", file_get_contents("/proc/loadavg"));
return $load[0];
}