I have been stumbling over this for a couple of days.
I have an imagick object $img that reads a pdf of two pages, in a webservice.
I am trying to save each page as jpg image.
for($i = 0;$i < $num_pages; $i++){
   file_put_contents(logfile,"index = ".$i." \r\n\r\n",FILE_APPEND);
   $img->setIteratorIndex($i);
   $img->writeImage('workorders/'.$jobSFID.$i.".jpg");
}
file_put_contents(logfile,"test 7 \r\n\r\n",FILE_APPEND);
When I remove the loop and save one page only... all goes well.
But with the loop, saving the two pages, it breaks down, never reaches test 7 logging statement, and gives 503 server temporarily unavailable some times, and other times 502 proxy error reading from remote server.
 
     
    