PHP maximum execution time - php

In my Plesk 11, PHP 5.4.7. Apache/2.4.3 system, when I make cron jobs I get this error from error.log file.
[Tue Mar 19 21:33:18 2013] [warn] [client 88.44.55.66] mod_fcgid: read data timeout in 45 seconds
[Tue Mar 19 21:33:18 2013] [error] [client 88.44.55.66] Premature end of script headers: index.php
So I checked for execution time with this:
echo ini_get('max_execution_time');
I got this value: 1560000
It doesn't seem a timeout problem but I get timeout error?
Answer for the future reference:
Edit /etc/httpd/conf.d/fcgid.conf file with vim.
Change FcgidIOTimeout 45 to FcgidIOTimeout 600.
Restart Apache.
Then Fast CGI timeout will be solved.

That's a mod_fcgid timeout, not a PHP timeout. Take a look at the mod_fcgid documentation to find out how to change it, especially at FcgidIOTimeout.

Cron scripts if build correctly should not be run through apache. Your error shows that you are running into a timeout set by mod_fcgi.

If you access it through http in your cronjob, then it will work as a webpage request and then it may be affected by apache timeout because apache is involved in the process. You can run the php script directly with an absolute path using php interpreter to bypass apache

Related

How to detect and log long time taking requests and connection timeout requests

question is pretty simple even if not so obvious.
I managing a website that's showing issues with connection timeout, making the web service unaccessible and not working properly when it happens.
The actual environment is WooCommerce on a self-managed secured VPS.
php7, php-fpm, wordpress 5.+, apache2, mysql, cPanel, centOs
For a couple of time the site became unreachable showing Connection Timeout error, even if all services was up and running.
How to track or log requests originating the connection timeout error?
For example, with an application ran on the server that:
log every requests that occurs with more than 30 seconds execution time
the moment of the request
the request URL.
Any software, wordpress, cPanel extension or service in order to detect the issue?
I get the solution in matter of detecting the situation when it happens.
The key information can be found in PHP-FPM log (deducted that by the fact that restarting PHP-FPM and not Apache2 was solving the problem, due to a probable PHP-FPM thread appended).
i.e., in a cPanel enviroment you would find the log at the path:
/opt/cpanel/ea-php$$/root/usr/var/log/php-fpm/error.log
In the file the following lines are noteful:
[Tue Jul 16 09:55:30.677693 2019] [proxy_fcgi:error] [pid 17283] (70007)The timeout specified has expired: [client 162.158.91.192:16946] AH01075: Error dispatching request to : (polling), referer: https://www.example.com/my-resource.php
[Tue Jul 16 10:00:30.738947 2019] [proxy_fcgi:error] [pid 17283] (70007)The timeout specified has expired: [client 162.158.91.192:16946] AH01075: Error dispatching request to : (polling), referer: https://www.example.com/my-resource.php
So I've been able to inspect the shown resource and replicate and solve the issue.

apache stop responding then crashes

Apache (2.4.25 FPM/FastCGI) stop responding and crashes after a while on my wordpress multisite website.
For some reason it used to run fine several days until I changed the wordpress(mu) domain using this script github.com/interconnectit/Search-Replace-DB (probably not the reason).
When restarted it works for about an hour then choked again.
I have added a mysql slow query log but its empty.
Apache error_log has multiple errors like this one:
[Wed Sep 06 08:50:27.941819 2017] [proxy_fcgi:error] [pid 25444:tid 140610719610624] (70007)The timeout specified has expired: [client x.x.x.x:53398] AH01075: Error dispatching request to : (polling)
and occasionally this error appears too:
[Wed Sep 06 09:13:33.296777 2017] [core:notice] [pid 10710:tid 140611211331392] AH00051: child pid 25582 exit signal Segmentation fault (11), possible coredump in /opt/bitnami/apache2
another occasional error (expected due to the multiple AH01075 timeout errors):
[Mon Sep 04 20:18:58.758718 2017] [mpm_event:error] [pid 19928:tid 140675798046528] AH00484: server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting
Stopping mysql server kills my site but seems to keep apache working fine, at least for an hour or two that i`ve been testing.
Is 457452 value is normal for mysqld.bin in the following process list? (ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNS)
2128 /sbin/init
2400 php-fpm: master process (/opt/bitnami/php/etc/php-fpm.conf)
3840 -bash
4244 sshd: ubuntu [priv]
6928 /usr/bin/gonit
11036 /opt/bitnami/apache2/bin/httpd.bin -f /opt/bitnami/apache2/conf/httpd.conf -DDISABLE_BANNER
11320 /opt/bitnami/apache2/bin/httpd.bin -f /opt/bitnami/apache2/conf/httpd.conf -DDISABLE_BANNER
11364 /opt/bitnami/apache2/bin/httpd.bin -f /opt/bitnami/apache2/conf/httpd.conf -DDISABLE_BANNER
11592 /opt/bitnami/apache2/bin/httpd.bin -f /opt/bitnami/apache2/conf/httpd.conf -DDISABLE_BANNER
20592 /opt/bitnami/apache2/bin/httpd.bin -f /opt/bitnami/apache2/conf/httpd.conf -DDISABLE_BANNER
57668 php-fpm: pool wordpress
57716 php-fpm: pool wordpress
65252 php-fpm: pool wordpress
67608 php-fpm: pool wordpress
68776 php-fpm: pool wordpress
457452 /opt/bitnami/mysql/bin/mysqld.bin --defaults-file=/opt/bitnami/mysql/my.cnf --basedir=/opt/bi
PHP Version 5.6.30
mysql.bin Ver 14.14 Distrib 5.6.36
Ubuntu 14.04.5 (bitnami image on AWS)
Memory usage while apache not responding: used:883mb of 992mb
php.ini script memory_limit = 128M
Was a bit long to put it in a comment, so replying as an answer.
Are you logging any php errors? From what you presented so far, my theory would be that:
You used that script to do a search & replace of db but it executed poorly causing malformed or corrupted data.
That caused your php scripts that rely on mysql to go haywire due to malformed or corrupted data.
Because your php on fcgi isn't responding, your apache waits for it and holds onto the resources.
All the requests are hanging and now you run out of resources and start seg-faulting.
And then stupid apache, seeing that you're out of child count asks you to raise it not realizing you're already exhausted on physical resource beyond reason. Typical apache...
Because apache is now out of free children, it can't take anymore requests and it appears as if all of apache is broken even though it's merely clogged up by bad fcgi processes.
If my theory is correct, you should.
Check that none of the mysql data is corrupted
Check that the data that was replaced in mysql was as what you expected
Check for PHP error logs as they should be logging something if they can.
You should isolate the PHP processes that are actually the cause of clogging up and remove it if cleaning up data alone wasn't enough. Ideally, no matter how bad the data, the php program should've died cleanly.
Good luck hunting.

60 sec timeout, unable to find the right param to fix it

My website exits (error 500) if a script takes more than 60 sec to be executed, but i don't understand why.
Phpinfo:
max_execution_time = 600
max_input_time = 600
In my httpd.conf file:
timeout = 600
So i don't get how to increase this parameter.
I found in my phpinfo (but i have no idea if it's related or not):
default_socket_timeout = 60
mysql.connect_timeout = 60
I think the mysql.connect_timeout is not related at all (i got the error on a page with a sleep(65); only...)
I finaly found the answer !
I will share the answer since i think it may help someone else !
I found in the apache error_log the following :
[Tue Jul 09 15:17:47 2013] [warn] [client 212.198.111.252] mod_fcgid: read data timeout in 45 seconds
[Tue Jul 09 15:17:47 2013] [error] [client 212.198.111.252] Premature end of script headers: test_max_execution.php
I then modified a file located in /etc/httpd/conf.d/ named fcgid.conf
I increased 3 parameters (FcgidIOtimeout, FcgidIdleTimeout & FcgidConnectTimeout) and everything seems to work properly now !
Have a nice day and thank you for paying attention to my question !
Frederic
Have a look at…
PHP set_time_limit()
PHP Runtime Configuration
…and:
MySQL server has gone away - in exactly 60 seconds
Happy reading :-)

How to fix FastCGI timeout issues in Plesk?

PHP support is currently set to: run as Fast CGI.
I keep getting these errors in my server log:
mod_fcgid: read data timeout in 45 seconds
Premature end of script headers: index.php
Should be quick fix I think, but I cant find the file to edit. Is this something I can change from Plesk.
Anyone know how to increase the timeout?
In Plesk 12.x and similar go to Web Server Settings and set the following directives:
Additional directives for HTTP & HTTPS
FcgidBusyTimeout 300
FcgidIOTimeout 250
Above lines will change the timeout for scripts that are quiet too long and take too long to execute.
Additional nginx directives
proxy_read_timeout 300;
Above lines will change the proxy timeout.
If the problem persist, increase the values.
See also: Premature end of script headers: index.php, mod_fcgid: read data timeout
Check the screenshots for the guidance:
A solution provided in the forum of Plesk by Parallels staff
Edit the file:
/etc/httpd/conf.d/fcgid.conf
Specifically, change
FcgidIOTimeout 45
to
FcgidIOTimeout 3600
3600 seconds = 1 hour. Should be long enough for most but adjust
upwards if required. I saw one example quoting 7200 seconds in there.
Finally, restart Apache to make the new setting active.
apachectl graceful
Hope it helps
R
My solution to this was to change the PHP settings in the plesk control pannel as per the screenshot.PHP Settings
In the new version of Plesk the fcgid.conf file has moved to:
/etc/apache2/mods-available/fcgid.conf
I had some issues importing an xml file into wordpress. It kept on giving a 500 Internal Error. The error log showed:
[Wed Jul 26 13:18:00.219226 2017] [fcgid:warn] [pid 4751] [client
145.97.205.8:60155] mod_fcgid: read data timeout in 45 seconds
[Wed Jul 26 13:18:00.219505 2017] [fcgid:warn] [pid 4751]
(110)Connection timed out: [client 145.97.205.8:60155] mod_fcgid:
ap_pass_brigade failed in handle_request_ipc function
After following some advice - as the PHP.INI settings made no difference - i changed some settings as advised:
Original:
FcgidIOTimeout 45
To:
FcgidIOTimeout 3600
Also added:
<IfModule mod_fcgid.c>
FcgidMaxRequestsPerProcess 500
<IfModule !mod_fastcgi.c>
Worked like a charm. Thank you for your help.
After changing max_execution_time = 3600 in /etc/php.ini solved my problem.

Php - Bulk post 500 Apache Internal Server Error

I've a script which send just a lot of data in json format
by post.
Up to about 10Mb (data are put into a flat file) of data the script works great but
if the load is higher I get from apache 500 Internal Server Error.
I peeped into apache log file I get
[Wed Jan 19 17:26:41 2011] [error] [client ip] Premature end of script headers: index.php
[Wed Jan 19 17:26:41 2011] [debug] mod_deflate.c(615): [client ip] Zlib: Compressed 632 to 385 : URL /index.php
Do you have any idea about it ?
Bye.
Premature end of script headers
This message means the PHP script died before outputing any content-type to apache. If you have ob_* functions activated it could be any error on your PHP script, or a timeout, check your set-time-limit parameter in PHP for timeouts.
Check as well that your exception handling output the correct content type if you want to output an error message.
To check all parameters that can have an impact you must check the timeout parameters and the size limits ones. Here are some of them:
Apache:
LimitRequestBody
PHP:
post_max_size
upload_max_filesize
max_input_time
max_execution_time
and maybe memory_limit as well

Categories