The weirdest thing happened today. When I run this query:
DELETE FROM some_table WHERE id IN(5)
I get a 30 second timeout error in PHP. The same query runs without issues on my local development server, but when I move it to the production server, I get the timeout.
No sqlite error or anything like that, just "Fatal error: Maximum execution time of 30 seconds exceeded " :|
What could be the problem? Is there any way I could debug this at least?
In top of all my new codes I put this function
ini_set('max_execution_time',60);
reference .
to debug my script execute time I use this
$start = microtime(true);
function execute(){global $start;$end = microtime(true);$time=number_format(($end - $start), 5);return$time;}
//..... your code here
echo '<br><b>.'Page Loaded In 'execute().' Seconds<b/>';
Related
So I am not familiar with servers, so please forgive me if I say something stupid.
the problem is that I work with a very old database and it's queries take very long to execute (about 1.5 minutes). when I use this in my website the server can't handel it and give's me a 503 error.
I tried checking how long the server runtime is with this:
echo $maxlifetime = ini_get("session.gc_maxlifetime");
but after a bit of reading I heard this is not the way to do it.
So my question is how do I see the time the server has to load the page before it give's me the 503 error and how do I lengthen it?
thank you for helping.
EDIT
oke this is the query that give's me the error:
SELECT FD_DATUM_INGEVOERD || ' ' || FT_TIJD_INGEVOERD FROM BANDZENDINGEN WHERE FB_AFGESLOTEN = 'F' AND FB_AKTIEF = 'T' AND FI_AFVOERKANAAL = 11 AND FI_GEBRUIKER1 = '175' AND FI_VERRIJKINGID < 1
it only takes 17 sec to execute in the firebird database.
EDIT 2
it just found out my queries only take a long time if the database is very busy with something.
oke just found the answer I will lenghten the execution time of the server with this:
ini_set('max_execution_time', 0);
I am working on a report section where user can access their set of data by year and dates
so there will be more then 5 to 6 queries in the api to retrieve the analytical data from the database. but the issue i am facing is it is getting timeout and returning a Error page of timeout in response instead i want to show custom error message to reduce the time interval of the dates Like "Please reduce the interval between dates to retrieve the data"
So how i can achieve this.Try catch i have used but didnt worked for me
try
{
$data1 =Database->Query1();
$data2 =Database->Query2();
$data3 =Database->Query3();
$data4 =Database->Query4();
$data5 =Database->Query5();
}catch(/Exception $exception){
#Show_custom_error
}
is there any other way by i can achieve this ?
You can set_time_limit in your script file or set it for the entire php installation in your php.ini file. Have a look at the link.
Also checkout this SO question/answers How to catch the fatal error: Maximum execution time of 30 seconds exceeded in PHP
I am facing this problem, firstly I would like to say that I am very new to PHP and MySQL.
Fatal error: Maximum execution time of 30 seconds exceeded in
.........................\cdn\wished.php on line 3
I don't know what is wrong in line 3, its giving error only sometimes. Here's my code:
<?php
//wished.php
$CheckQuery = mysql_query("SELECT * FROM users WHERE ownerid='$user->id'");
$wished = 0;
while($row = mysql_fetch_assoc($CheckQuery))
{
// echo $row['fname']."<br/>";
$wished++;
}
echo $wished;
?>
It was perfect when I run this in localhost with XAMPP. As soon as I hosted my app on my domain and used their database, it start getting error.
thanks every one :)
The issue is that the SQL query is taking too long, and your production PHP configuration has the PHP script time limit set too low.
At the beginning of the script you can add more time to the PHP time limit:
http://php.net/manual/en/function.set-time-limit.php
set_time_limit(60);
for example to add 30 more seconds (or use 0 to let the PHP script continue running).
If your production database is different than your development DB (and I'm assuming production has way more data) then it might be a really expensive call to get everything from the user table.
I have this PHP code:
<?php
include_once("connect_to_mysql.php");
$max=300;
while($max--)
{
sleep(1);
doMyThings();
}
?>
it is supposed to repeat a mysql query 300 times with gap of 1 second between each. But the problem is after a minute or so in the browser i get this message: No Data Received. Unable to load the webpage because the server sent no data.
The problem is the following: Your code will at least (without considering the amount of time needed by doMyThings()) last 300 seconds. Most PHP environments set the default script running time to about 60 secs, the script stops and nothing is printed out.
Next thing is (if script execution time is set high enough to allow long running scripts), the script has to run until its finished (that is, ~300 secs) and after that, data is written onto the output stream. Until there, you won't see any output.
To circumvent those two problems, see this code:
<?php
// If allowed, unlimited script execution time
set_time_limit(0);
// End output buffering
ob_end_flush();
include_once("connect_to_mysql.php");
$max=300;
// End output buffering IE and Safari Workaround
// They will only display the webpage if it's completely loaded or
// at least 5000 bytes have been "printed".
for($i=0;$i<5000;$i++)
{
echo ' ';
}
while($max > 0)
{
sleep(1);
doMyThings();
$max--;
// Manual output buffering
ob_flush();
flush();
}
?>
Maybe this post is also of interest to you: Outputting exec() ping result progressively
The browser will not wait a whole 5 minutes for you to complete your queries.
You need to find a different solution. Consider executing the PHP script in CLI.
It seems that you have a timeout executing 300 times doMyThings();
You can try with set_time_limit(0);
Set the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error. The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php.ini.
When you execute long time php code on server side, you need change max_execution_time directive in php.ini. But browser will not wait how long as you want so you need use async technology like AJAX
I'm using a recursive function to do some calculation for every user and reward them for certain condition. Everything was working fine, but now that my user number has increased to something like 20000+ my script cannot be completed... my code is like
function give_award($mid) {
$qry = mysql_query("SELECT * FROM users WHERE uid='$mid'");
while($row=mysql_fetch_array_result)
{
$refer = $row["refer"];
}
//some conditions applied
//query for user award
//if succeed
$mid = $mid+1;
give_award($mid)
}
give_award($mid);
I'm Sure give_award(); isn't doing the time out in a single time calling. Is there a way that I can reset the time limit every time before the function is recursively (re)called?
Ways I've tried:
set_time_limit(0);
changing the timeout limit in .htaccess
changing apache timeout limit in php.ini
NB: No fatal error was show... But I've to restart apache every time I try to run this on local server... Using Zend Server Community edition on Win7 32bit.
Please help
I don't know where to find the recursion limit, but this is not a place to use it as far as I can tell anyway. A quick test here:
<?php
function KillingRecurse($r){
echo $r.PHP_EOL;
KillingRecurse(++$r);
}
KillingRecurse(0);
Result:
...
20916
Segmentation fault
I'm not surprised a segfault causes the server to need to be restarted, and the numbers kind of match up.
Tell us more about what you are trying to do here, because recursing through all users seems maddness here...