You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
set_time_limit() counts time while pg_get_result() waiting for asynchronous PostgreSQL query #14769
<?php// Connect$conn = pg_connect("dbname='somedb'");
// Send a postgres sleep query (or anything long running query)pg_send_query($conn, "SELECT pg_sleep(5)");
// Set PHP max execution time less than aboveset_time_limit(2);
// Waiting for query to complete (but fails and error is shown)$res = pg_get_result($conn);
// Never printedecho"OK";
Resulted in this output:
PHP Fatal error: maximum execution time of 2 seconds exceeded
The code worked as expected in PHP 8.1, until I upgraded to PHP 8.3. I think it should not count time while the PHP script is doing nothing but waiting for the PostgreSQL server. I did not find any documentation about this change in code behaviour.
Thanks for the quick reply. Indeed, the code works as it should on Ubuntu, I tried it too. I have two very different Gentoo systems with PHP 8.3 and both produces the bug. I also tested PHP 8.2 on Gentoo (same configuration) and got the OK. It's weird, seems like a Gentoo specific bug on version 8.3.
I think I found the problem, the error depends on whether thread safety is enabled or not. If I compile PHP 8.3.8 on Gentoo without threads, the above code works as should. But if I compile PHP with POSIX threads, the code breaks. On Ubuntu the PHP 8.3.6 is compiled without threads, that's why it's working okay.
Even PHP's sleep() function times out with ZTS enabled:
<?php
ini_set('display_errors', '1');
echo PHP_VERSION . "\n";
// Setting execution time less than PHP sleep()
set_time_limit(2);
// PHP Fatal error: maximum execution time of 2 seconds exceeded
sleep(5);
// Never printed
echo "OK";
Was wrong about the commit, @lezso6, if you build from source, can you add --enable-zend-max-execution-timers=no to the ./configure command ? I forgot about that change ..
Activity
lezso6 commentedon Jul 2, 2024
The code worked as expected in PHP 8.1, until I upgraded to PHP 8.3. I think it should not count time while the PHP script is doing nothing but waiting for the PostgreSQL server. I did not find any documentation about this change in code behaviour.
devnexen commentedon Jul 2, 2024
I have tried with the following cases :
In every case I get my OK.
lezso6 commentedon Jul 2, 2024
Thanks for the quick reply. Indeed, the code works as it should on Ubuntu, I tried it too. I have two very different Gentoo systems with PHP 8.3 and both produces the bug. I also tested PHP 8.2 on Gentoo (same configuration) and got the OK. It's weird, seems like a Gentoo specific bug on version 8.3.
MorganLOCode commentedon Jul 3, 2024
As another datapoint, 8.3.8 on Windows times out as well.
lezso6 commentedon Jul 3, 2024
I tried version 8.3.6 and 8.3.3 on Gentoo and both throws the error.
lezso6 commentedon Jul 3, 2024
I think I found the problem, the error depends on whether thread safety is enabled or not. If I compile PHP 8.3.8 on Gentoo without threads, the above code works as should. But if I compile PHP with POSIX threads, the code breaks. On Ubuntu the PHP 8.3.6 is compiled without threads, that's why it's working okay.
devnexen commentedon Jul 3, 2024
does it work with ZTS and in a non async way ? e.g. just pg_query
lezso6 commentedon Jul 3, 2024
Suprisingly, the script times out in non-async / blocking mode too:
devnexen commentedon Jul 5, 2024
I ll have a look in the following days.
devnexen commentedon Jul 7, 2024
Anybody using mysql ? If yes what happens with ZTS build with 'SELECT SLEEP(5)' query?
lezso6 commentedon Jul 7, 2024
I tried mysqli extension with MariaDB and the PHP script times out as well. Code:
lezso6 commentedon Jul 7, 2024
Even PHP's sleep() function times out with ZTS enabled:
Without ZTS, there is no timeout.
devnexen commentedon Jul 7, 2024
Ok gonna bisect it. I think that s better support Linux timeouts with ZTS part but will double-check.
devnexen commentedon Jul 7, 2024
Was wrong about the commit, @lezso6, if you build from source, can you add
--enable-zend-max-execution-timers=noto the ./configure command ? I forgot about that change ..lezso6 commentedon Jul 8, 2024
I recompiled with ZTS enabled and Zend Max Execution Timers disabled, and the bug is gone. It works, no timeouts.
devnexen commentedon Jul 8, 2024
It appears on the migration guide. Distribution packagers would need to modify their build workflow to take it into account.
lezso6 commentedon Jul 8, 2024
So if I understand correctly, this is a feature. And will be enabled for non-ZTS builds, I read that here: #6504 (comment)