1

I have a PHP script that takes about 30 seconds to complete. When running it through php cli it finishes successfully (echos a confirmation and saves relevant results in a file on a local file system). If I run the same file through Apache, it seems to time out or something, after about 30 seconds or so, instead of the expected confirmation message, Firefox offers me to download an empty file (other browsers treat it differently, but basically, something did not go as planned). The file that was supposed to be created on the filesystem is not created.

Knowing that the execution time could be long, I set set_time_limit(400) in the beginning of the script.

Any tips on how I could debug this? What could be causing the script to time out in Apache, but not in cli?

5
  • your hoster allow the set_time_limit ? Commented Jul 29, 2011 at 13:10
  • When you run scripts from the commandline there is never an execution limit enforced by PHP. This is one of the (minor) differences between PHP run from the commandline and PHP run as a (f)cgi or apache module. See: php.net/manual/en/features.commandline.php Commented Jul 29, 2011 at 13:12
  • Does your server has permission to write to specific location where you saving your file. Commented Jul 29, 2011 at 13:13
  • Yes, I can write files into that location, using other scripts on the same server. set_time_limit is allowed, and I set it to 400, as mentioned in my question. max_execution_time in php.ini is set to insane 2000 and there is only 1 php.ini file on the system. Commented Jul 29, 2011 at 13:19
  • Hey Salty give us a update, please. have you noticed the new answers? Commented Aug 2, 2011 at 13:14

3 Answers 3

1

after reading all answers and comments here, i believe that your script does not timeout.

i think its an crash of you application. the apache process runs in a restricted user your cli does not.

maybe you are writing a file to a folder, you do not have access to (under the apache user).

i is also possible that there are php modules missing. compare you cli php.ini to the apache php.ini.

turn on error logging:

error_log = /tmp/php_error.log
log_errors = 1

maybe you are in a test environment you may also enable display_errors. but turn this always off in production use!

see log why php aborts.

you can use the su command to run the php script from cli within the apache-account. this can be used to checks the rights.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, will try this and see what I can get.
0

additional to the php time limit the cgi can timeout. if you are using mod_fcgid with your apache you need also increase the time there.

take a look into the manual

i think you need to increase FcgidIOTimeout 40

5 Comments

It does not appear that I am using mod_fcgid - could not find it anywhere on the file system and no mention of FcgidIOTimeout in any apache config files.
maybe you are using mod_php. you can see your gateway within phpinfo(). Server API: CGI/FastCGI and $_SERVER["SERVER_SOFTWARE"] shows (see the end) Apache/2.2.14 (Win32) mod_ssl/2.2.14 OpenSSL/0.9.8k mod_fcgid/2.3.6
did not detect mod_php either. running it under linux centos, btw.
some manuals showing for centos the mod_fcgi. to detect which gateway you are using you maybe search for FcgidWrapper within your etc directory (and subs). if you find it you are using fcgi. also take a look at all LoadModule commands. if there is something like LoadModule php5_module modules/libphp5.so then you are using the apache module from php. this is also common on linux.
do have the LoadModule php5_module modules/libphp5.so line in config. aside from max_execution_time in php.ini and Timeout in apache config, what else could be setting a low timeout?
0

PHP CLI and PHP via Apache use different php.ini files. Check the php.ini file for the Apache version and confirm that max_execution_time is high enough to accomodate your needs.

You can execute phpinfo() to get the location of the currently-used php.ini file.

3 Comments

seems like there is only one php.ini on the system.
@SaltyNuts: Please see my updated answer. If you found the correct php.ini file, edit its set_time_limit directive and restart the webserver to see if the execution time limit increases.
with your instructions, I have confirmed that the max_execution_time is set to 2000 in php.ini. I assuming you meant max_execution_time instead of set_time_limit, since set_time_limit is a function, not a php.ini directive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.