Internal Server Error after long time running of php script - php

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.

Related

Getting a PHP maximum execution time error

I'm getting a PHP "Maximum execution time of 60 seconds exceeded" error even though the max_execution_time and max_input_time settings in my php.ini are set to 180. I also tried to make my script use set_time_limit(0); and ini_set('max_execution_time', 180); and that's not helping. I've made sure the right php.ini file is being used, checked phpinfo() output, all the setting values are what I'd expect them to be. The line of code throwing the error is calling curl_exec(), so I also try to add curl_setopt($ch, CURLOPT_TIMEOUT, 180); and no luck, still getting the same 60 second timeout error. Running out of ideas as to what other timeout setting could possibly be causing this. Environment is Windows with PHP running as FastCGI module.
Run ini_get() precisely where the call is failing and see if it yields the value expected. If not, searched your code for something overriding the value you're expecting.

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?

Ajax error - 0 after a long php script

I am using jquery ajax to send the url of a file (csv file) located on the server to my php script so as to process it.
The csv file contains telephone calls. If i have a file with even 10.000 calls everything is ok. But if i try a big file with like for example 20000 calls then i get an Ajax Error 0 . I check for server responce with firebug but i get none.
This behaviour occurs after like 40mins of w8ing for the php script to end. So why do i get this error on big files only? Does it have to do with apache, mysql or the server itself? Anyone able to help will be my personal hero cause this is driving me nuts.
I need a way to figure out whats happening exactly but firebug wont return a server responce. Any other way i can find out whats happening?
I checked the php error log and it reports nothing on the matter
Thanks in advance.
The script may have timed out:
See your php.ini file
max_execution_time
max_input_time ;# for the max time an input can be processed
Were your PHP.ini is depends on your enviroment, more information: http://php.net/manual/en/ini.php
Check:
max_input_time
This sets the maximum time in seconds a script is allowed to parse input data, like POST and GET. It is measured from the moment of receiving all data on the server to the start of script execution.
max_execution_time
This sets the maximum time in seconds a script is allowed to run before it is terminated by the parser. This helps prevent poorly written scripts from tying up the server. The default setting is 30. When running PHP from the command line the default setting is 0.
Also
Your web server can have other timeout configurations that may also interrupt PHP execution. Apache has a Timeout directive and IIS has a CGI timeout function. Both default to 300 seconds. See your web server documentation for specific details.
First enable php error by placing below code at top of the php file.
error_reporting(E_ALL);
Then as Shamil explained in this answer, checkout your max_execution_time settings of your php.
To check max_execution time, open your php.ini file and search for that, and then change it to a maximum value of say one hour (3600).
I hope this will fix your issue.
Thank you

PHP Fatal error: Max execution time exceeded - EVEN after set_time_limit(0)

I keep running into the following PHP error when running my script
Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\apps\sqlbuddy1.3.3\functions.php on line 22
I already put this in my PHP file, and I STILL get this error message.
#set_time_limit(0);
Am I missing something?
Edit: This error only shows up after SEVERAL minutes, not after 30 seconds. Could something also be delaying its appearance?
set_time_limit() has no effect when running in safe_mode:
This function has no effect when PHP is running in safe mode. There is no workaround other than turning off safe mode or changing the time limit in the php.ini.
You can check the value of safe_mode and max_execution_time with phpinfo().
Given the facts that you are using Windows and experiencing the timeout later than 30s you might have somewhere else in your code a reset of the timeout (set_time_limit(30)):
The set_time_limit() function [..] only affect the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), stream operations, database queries, etc. is not included when determining the maximum time that the script has been running. This is not true on Windows where the measured time is real.
Search your code for:
ini_set('max_execution_time', 30)
set_time_limit(30)
Rather than relying on the PHP file to change the php.ini settings, you should do it yourself. Find where the php.ini is kept for WAMP, and change/add this line:
max_execution_time = 500;
There is a PHP config that unallows the script to change the time_limit.
You can change your PHP behavior on php.ini file

How to Extend the Request/Connection Timeout on Apache-FastCGI-PHP application using .htaccess

I am trying to extend the Connection/Request Timeout at our allotted server space.
The Reason i am trying to do this is, for some operations in my application takes more than 120 seconds, then the server is not waiting for the operation to complete. It returns 500 Internal Server Error, exactly after 120 seconds.
To test it i placed the below script on server:
<?php
sleep(119);
echo "TEST";
?>
It will return TEST, to the browser after 119 seconds.
But when i place below script:
<?php
sleep(121);
echo "TEST";
?>
It will return 500 Internal Server Error after 120 seconds
we have set the Max_execution_time=360 in php.ini, but the problem still exists.
We have Apache installed with FastCGI.
I am trying to extend it to 360 seconds, using .htaccess, because that is the only way i can in Shared Hosting.
Any solutions or Suggestions ?, Thanks in Advance.
Fastcgi is a different beast; using set_time_limit will not solve the problem. I'm not sure what you can do with .htaccess, but the normal setting you're looking for is called IPCCommTimeout; you can try to change that in the .htaccess, I'm not sure if it's allowed or not.
See the directives on the apache fcgid page; if you're using an old version, you might need to try setting FcgidIOTimeout instead.
I would suggest that 120 seconds is far too long for a user to wait for a request over a web server; if things take this long to run, try running your script from the command line with PHP CLI instead.
Try this, hope it will work:
set_time_limit(int seconds)

Categories