Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I created a PHP script for generating image files, now I am using a combination of IMagick, ImageMagick to generate the JPEG image files.

Now the problem is that at a time a group of image files are generated, each group containing 4 image files(Front, Back, Left-Side, Right-Side)

Now usually the size of the Front image file is somewhere between 2Mb-4Mb while the size of Back Image file is anywhere between 1Mb-1.5Mb and that of the Sides are just 500Kb each.

Now as you can see the file sizes are big as the resolution are also big like 3600x3600 for both the Front and the Back as for the Sides it is 200x3600 (WidthxHeight)

Now the problem is that sometimes this script for genereting these files run perfectly fine but at other times it just stops without completely generating all the files.

Like for example sometimes it will create all the 4 files, but at other times, it will stop at the Front Image file or maybe after creating the Front it will stop at Back Image file.

And when this happens sometimes the apache webserver just stops responding, I mean it just hangs-up and I have to restart it through the SSH Client.

I am fairly new to the platform of PHP-Apache-MySQL so I am still learning, so I apologize if I am making some stupid mistake, but I have no clue what is happening or why is it happening.

I am assuming that the problem could be due to WebServer overloading because it takes the Server entire 4-5 seconds to generate the Front Image file then 2-3 seconds to generate the Back Image file and about 1 second to generate each of the Side image files.

So if it is due to WebServer getting overloaded can someone please tell me how can I avoid it???

Also what is the purpose of buffer setting in php.ini file, I mean could this effect the outcome when the server is getting overloaded???


Sorry I forgot to mention that I also checked the error logs, no errors over there, Also the execution time is set at 60 minutes, Max memory usage is set at 512Mb for this particular script.

The problem is that this problem is rare, I mean the script will execute perfectly fine for 8 times out of 10. So there is no pattern over here it's totally random.


Also this script is running in the background, I mean some other script make a asynchronous AJAX Request to the Image Generation Script, the image generation script simply runs in the background generating the image file, it doesn't return any output and it also ignores any user_abort, so the user is free to close the browser once the AJAX Request has been made to the Image Generation Script.

And Yes I tried to run this script in the Foreground by running it in an new tab of the browser window, if the script ran completely then no output as expected, only that when I check the files all the 4 files are there in complete form.

But when there is an error, I just get a message on my FireFox browser that the connection to the Server has been reset(this message is given by FireFox and not by my code in FireFox format), after this when I check the files I see that only some of the 4 files have been created. Also the timeout for this script has been set to 60 minutes. The FireFox connection reset error get's displayed within 2 minutes time. The max-timeout setting in PHP.ini is set at 30 minutes.

Also it's not like it always creates a problem if the script is taking 2 minutes time to complete it's work, sometimes the script takes 3-4 minutes time, but finishes the work and sometimes it just stops working after 10-20-30 seconds so it is very random. I checked the code multiple times and there is nothing wrong over here because if it were then the frequescy of this problem would have been much higher, right now it is only 10-20% of the time.

share|improve this question
1  
Do you have errors displayed? Have you checked the error log for both PHP and Apache? They will give you hints as to whats causing the issue. – Phil Cross May 23 at 7:03
Might just be max execution time – Orangepill May 23 at 7:11
3  
Try set_time_limit(0); at the top of you script. – Orangepill May 23 at 7:15
there is no error in the error-log relating to this php script, also the max-execution time is set at 60 minutes and the normal execution of this file only takes 20-30 seconds max(if no errors) – Aditya May 23 at 7:22
Excuse the silly question but are you sure you checked the right log? eg both Apache logs and PHP error logs? If it's not a timeout thing, it may be memory-related OOM sometimes causes a fairly abrupt halt. As an aside, buffer merely signals whether the return contents should be buffered server-side, allowing things like adding headers/modifying contents after you've started writing output. – Basic May 23 at 7:31
show 2 more comments

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.