504 Gateway Time-out Error on PHP Script - php

I coded a script for database import, it makes a few jobs on database. When I work this script, after a few minutes I'm getting "504 Gateway Timeout Error".
I increased all timeout values on php.ini, also I increased execution times but it is still same.

You can increase maximum execution time in php.
ini_set('max_execution_time', 300); //300 seconds = 5 minutes

Write an info file on your server containing
<?php phpinfo();
View the file in your browser and check the max_execution_time
If it's 0 then there is something different to do else make sure you changed on correct ini file.
You can also check your ini file location
If you still can't fix it please reply :)

Related

Fatal error: Maximum execution time of 30 seconds exceeded. How to handle this error?

I am getting this error while running one script.
I know it's about execution time and i had went through all answers too but i want to display custom message when this error occurs so that site doesn't break.
How to handle that error as i have kept error display off on my live site so footer is not loaded due to this error which stops breaking my site?
http://whois.icann.org/en/lookup?name=google.com
When you visit this site its displaying custom error message
You can either increase the maximum execution time by using set_time_limit() or by setting max_execution_time in the php.ini.
Also by setting set_time_limit to 0 you can remove the limit for exceution time.
And if you are using linux you can try with the function register_shutdown_function.This function will be called when the execution time limit is reached.
You can try to add this line of code in the file first:
set_time_limit(0)
You can always modify your php.ini file. There is a setting for maximum execution time.
Another way is to use ini_set function.
Another way is to put the max execution time in your htaccess file.
EDIT:
The max execution time is not an error and therefore not catchable.
Please check out this: http://stackoverflow.com/questions/6861033/how-to-catch-the-fatal-error-maximum-execution-time-of-30-seconds-exceeded-in-p
Finally, there is always scope of fixing the scripts and putting lengthy processes into a queue.
you can exceed max execution time like this :
ini_set('max_execution_time', 300); //300 seconds = 5 minutes
change below configuration in php.ini
max_execution_time = 600;
max_input_time = 120;
max_input_nesting_level = 64;
memory_limit = 128M;
ini_set('memory_limit', '-1');
ini_set('max_execution_time', '10000');
at the first line of your php code

How to prevent timeout when running a time consuming PHP

I am using PHP that gets so many data from several sites and write those data to the server which make files greater than 500 MB, but the process fails in between giving a 500 INTERNAL ERROR, how to adjust the timeout time of the php so that the process runs till it is completed.
If you want to increase the maximum execution time for your scripts, then just change the value of the following setting in your php.ini file-
max_execution_time = 60
If you want more memory for your scripts, then change this-
memory_limit = 128M
One more thing, if you keep on processing the input(GET or POST), then you need to increase this as well-
max_input_time = 60
you have to set some settings in the php.ini to solve this problem.
There are some options which could be the problem.
Could you pls post your php.ini config?
Which kind of webserver do you use?Apache?

MYSQL The connection has timed out even I have defined in php.ini

I am running some reports and those reports takes more than 300 seconds to execute and finally display on browser.
I have already defined the max execution time in my code and also set the same in php.ini.
ini_set('max_execution_time', 500);
I am using MySQL Workbench to monitor the execution but on 300 sec browser shows
The connection has timed out. The server at localhost is taking too long to
respond.
I just need to extend it to 400-500 sec and all of my reports will start working smoothly.
How can I do that?
Have you tried this:
ini_set('max_execution_time', 0);
This set the maximum execution time to unlimited. You could set this right before calling your report and set it back to a regular value, e.g 300 right after your report is done.
Your web server can have other Timeout configurations settings that may also interrupt PHP execution. Apache has a Timeout Directive which has default value to 300 seconds. Try changing the directive in your conf (httpd.conf for Apache) file.
For more details , See Apache Timeout Directive doc.

Internal Server Error after long time running of php script

I have some db query in my php file, approximately after 40 second, happened INTERNAL SERVER ERROR, though in php.ini file this settings are set:
memory_limit 8192M
max_execution_time 120
I think this settingst is enough, other what reason may causes INTERNAL SERVER ERROR after long time running of php script?
set
ini_set('max_execution_time' ,0);
ini_set('set_memory_limit', -1)
The question is old but this might work for someone.
Use this for every iteration of your loop sleep(0.5);
0.5 is user defined you can change it.

PHP script timeout in Log Analyzer

I have been trying to get Log Analyzer to work for longer than I care to admit. I can't seem to get syslog messages to display in the Log Analyzer web-GUI, but this morning I got the following error:
"While reading the logstream, the php script timeout forced me to abort at this point. If you want to avoid this, please increase the LogAnalyzer script timeout in your config.php. If the user system is installed, you can do that in Admin Center."
I was not getting this error on Friday; only "No syslog records found." The timeout is set to 30 seconds in the config file, but I read that setting will get overwritten back to the default anyway. The database grew to over 4GB over the weekend. Does the the db size have anything to do with this?
It's pretty clear I am new to php and Log Analyzer, so any help with both would be greatly appreciated. I can post config file settings if needed.
Try to increase time. 30 second may be not enough for parse large file. For example set 600 seconds.
Another case to increase timeout - edit following line in php.ini file
; Duration of time, in seconds for which to cache realpath information for a given
; Maximum execution time of each script, in seconds
; http://php.net/max-execution-time
max_execution_time = 30;
Too many records in the database, the script does not have enough time to process everything. I keep the last 14 days in the database, that's enough.
USE Syslog;
DELETE FROM Syslog.SystemEvents WHERE ReceivedAt < DATE_SUB(NOW(), INTERVAL 14 DAY);

Categories