Replies: 7 comments 1 reply
-
|
|
Beta Was this translation helpful? Give feedback.
-
|
it's not a credentials problem because the first connexion is successful |
Beta Was this translation helpful? Give feedback.
-
|
You mean $_SERVER is not destroyed between requests ? I thought $_SERVER is not for defining vars but only for retrieving server provided vars |
Beta Was this translation helpful? Give feedback.
-
|
Yay ! I finally solved it. Thanks to Perplexity AI ! Here is my final index.php (worker file) , I had to include almost everything in the $handler my database connection method : Now running ab -n 1000 -c 64 https://mydomain gives me 2.5ms per request instead of 4ms ! |
Beta Was this translation helpful? Give feedback.
-
|
oops , there are still errors on php error log when I run ab -n 1000 -c 64 https://mydomain/ So how to connect many requests in worker mode using always the same PDO object ? |
Beta Was this translation helpful? Give feedback.
-
|
YAY ! it solved quickly by adding PDO::ATTR_PERSISTENT => true in the PDO options |
Beta Was this translation helpful? Give feedback.
-
|
You should probably put the setup logic for the container outside of the handler. That will make it so you only have to set up once (and only create the connection once). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm starting to experiment with worker mode with a PHP application that doesn't use any framework.
I see that in xdebug as soon as I start my docker server, Frankenphp launches 4 requests to my worker.php file
Then, as soon as I reach the frankenphp_handle_request() function, I'm taken to the next request. And then my $pdo object, or even if I name it $GLOBALS['pdo'], is destroyed.
so this code doesn't work:
in php error.log I get :
[09-Mar-2025 11:40:15 Europe/Paris] PHP Fatal error : Uncaught Exception : Database connection failed : SQLSTATE[HY000] [2002] Connection refused in /app/html/public/index.php:34
probably because there was already a connection to the database during the previous query.
yet my PDO connection code is outside the $handler :
Beta Was this translation helpful? Give feedback.
All reactions