1 (edited by chrizz 2005-02-22 07:35)

Topic: imagemagick with system("convert ..."); hangs up php

I use imagemagick (convert) to resize images on my site.

it looks something like:

system("convert -size 1280x1280 /var/www/t/DSC_0320.JPG -resize 1280x1280 -quality 75 /var/www/t2/DSC_0320.JPG");

If i have this in a loop with more images it will hang up PHP and no access what so ever can be made to other pages. All the processes must be done before php works again.

I read this in the manual for system() (http://se.php.net/manual/en/function.system.php)

"Note: If you start a program using this function and want to leave it running in the background, you have to make sure that the output of that program is redirected to a file or some other output stream or else PHP will hang until the execution of the program ends."

What that means I'm not 100% sure of, but i've tried adding &>/dev/null at the end so the system above looks like this:

system("convert -size 1280x1280 /var/www/t/DSC_0320.JPG -resize 1280x1280 -quality 75 /var/www/t2/DSC_0320.JPG &>/dev/null");

That still hangs upp php until all processes are done. PLEASE! This is horrible if I want to update 200 images that takes 30 minutes or so. The whole site will be down for the whole time. Thats not acceptable. Please help me smile


Btw. I run debian linux with apache and mysql.

Re: imagemagick with system("convert ..."); hangs up php

Problem solved, solution for those who are intressted:

The reason for why it hangs up is that I use session. By running session_write_close() before and start_session() again after all the system() (or exec) funktions it works just fine.