Yet Another Cycling Forum

General Category => The Knowledge => Ctrl-Alt-Del => Topic started by: Diver300 on 24 February, 2019, 04:00:30 pm

Title: php 7.2.15 timeout.
Post by: Diver300 on 24 February, 2019, 04:00:30 pm
Ionos, who host my vehicle tracking website, have recently changed to php 7.2.15

One page that processes lots of data, which used to run fine, now times out and doesn't finish. It is a report that is only run weekly, so it doesn't matter that it takes a few minutes to run.

While I can't give the esteemed YACF members access to a load of data about where the vehicles have been, I've put together a page that times out in the same way.

It's here:- http://www.mtrak.co.uk/timeout.php (http://www.mtrak.co.uk/timeout.php)

The count should get to 100, but it just stops after what I think is 30 seconds of execution time. The time (in ms) comes from a function that uses getrusage that I'm only using for diagnostics but I don't fully understand.

When I try to change the timeout with

either set_time_limit(1000)
or ini_set('max_execution_time',300)

then the code stops after 50 seconds with no warning. Those can be seen here:-
http://www.mtrak.co.uk/timeout.php?s=1 (http://www.mtrak.co.uk/timeout.php?s=1)
http://www.mtrak.co.uk/timeout.php?i=1 (http://www.mtrak.co.uk/timeout.php?i=1)

The information about the php version is here:-
http://www.mtrak.co.uk/info.php (http://www.mtrak.co.uk/info.php)

The php code for the timeout demonstration page is:-
Code: [Select]
<?php

error_reporting
(E_ALL);

$rustart getrusage();

if (isset(
$_GET['i'])){ini_set('max_execution_time',300);}
if (isset(
$_GET['s'])){set_time_limit(1000);}

function rutime($ru$rus$index) {
    return (
$ru["ru_$index.tv_sec"]*1000 intval($ru["ru_$index.tv_usec"]/1000))
     -  (
$rus["ru_$index.tv_sec"]*1000 intval($rus["ru_$index.tv_usec"]/1000));
}
$a 1;
while (
$a 100)
{
$ru getrusage();
echo $a .' Time so far:' rutime($ru$rustart"utime") . '<br/>';
$a++;
$b 0;
while ($b 10000000)
{
$c=0;
while ($c 5)
{
$c++;
}
$b++;
}
}
?>



Title: Re: php 7.2.15 timeout.
Post by: Pickled Onion on 24 February, 2019, 08:52:12 pm
The max_execution_time in your php.ini is thirty seconds, so that explains the first one. The fact that you don't get a fatal in the second test suggests it's not php that's timing out. Possibly an apache directive imposed by your isp? I'm guessing apache, it may be possible to override it, if that's what it is.

If your report is for you only and is against a database, can you just run it from your local machine rather than through a web page?

By-the-by, if you're on shared hosting running a tight loop is not the friendliest way of simulating sleep().
Title: Re: php 7.2.15 timeout.
Post by: philip on 24 February, 2019, 09:42:09 pm
If PHP was upgraded then it is possible that Apache httpd was also upgraded.  The default httpd timeout was reduced from 300s in 2.2 to 60s in 2.4:

https://httpd.apache.org/docs/2.2/mod/core.html#timeout
https://httpd.apache.org/docs/2.4/mod/core.html#timeout
Title: Re: php 7.2.15 timeout.
Post by: Diver300 on 25 February, 2019, 12:22:25 pm
The max_execution_time in your php.ini is thirty seconds, so that explains the first one.
Yes, I realised that. I wanted to show that max_execution_time was doing something.

The fact that you don't get a fatal in the second test suggests it's not php that's timing out. Possibly an apache directive imposed by your isp? I'm guessing apache, it may be possible to override it, if that's what it is.
It could be Apache.  Philip's reply would indicate that possibility. I will follow that up later.

If your report is for you only and is against a database, can you just run it from your local machine rather than through a web page?
The database is for the owner of the vehicles with the tracking units, and the database isn't local.
I suppose that I could split the job up somehow, and stick the results back together with another routine, but it is a bit of a pain to do.

By-the-by, if you're on shared hosting running a tight loop is not the friendliest way of simulating sleep().
I see that, but my code was just to simulate the other code not running, and will be deleted when the problem is solved.
Title: Re: php 7.2.15 timeout.
Post by: Pickled Onion on 28 February, 2019, 08:00:00 am
The database is for the owner of the vehicles with the tracking units, and the database isn't local.

It doesn't need to be, just stick the location of the server in your connection string, most ISPs allow database log in from anywhere.

If you meant "The report is for the owner..." then why not generate the report in a cron job and write it out as a static web page, then they won't have a two minute lag when they want to see it.