PHP 8.1 start_session() hangs/freezes indefinitely (script "loads" forever, no error/output)

Operating System & Version
CentOS v7.9
cPanel & WHM Version
WHM 106.0.14

Benjamin D.

Well-Known Member
Jan 28, 2016
205
33
78
Canada
cPanel Access Level
Root Administrator
I've begun slowly migrating websites on this WHM 106.0.14 server from PHP 7.4 to PHP 8.1 since PHP 7 has now fully reached end of life. PHP 8.1 was installed via EasyApache 4.

I'm running into a weird issue that I've never had to deal with in over 20 years of using PHP on various servers and I suspect there's additional configuration in WHM (probably in httpd.conf or php.ini, not sure yet) that needs to be done before PHP 8.1 can be used "normally".

I made a new PHP file with only the following content in it (sorry, I tried to format the code, but when I click on the CODE button in the editor toolbar, it pops up cpanel.net list of forums for some reason)
<?
session_start();
die('OK');
?>

And then when I request this file in a web browser, the script hangs and never finishes loading (it does not output "OK" or anything else). There is no error_log file either. I left it hanging like that for 5 minutes and it never stops "loading". In WHM the CPU usage for that script goes in the roof to near 100% in seconds.

I went to take a look in /var/cpanel/php/sessions/ea-php81 and I can see 7 bytes session files in there so I know PHP creates them, it looks good.

I'm kind of stumped. Is there anything that needs to be tweaked in WHM anywhere for PHP 8.1 to correctly execute the session_start() function? Never had any problem with previous PHP releases...
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
14,252
2,219
363
cPanel Access Level
Root Administrator
Hey there! I'm not able to reproduce this on my end. My browser shows "OK" when I load this test page on a domain running PHP 8.1.

What happens if you try and execute it directly on the command line? I get this on my system:

Code:
# /usr/bin/ea-php81 phptest.php
X-Powered-By: PHP/8.1.14
Set-Cookie: PHPSESSID=95b86039c4abf46bc2769f38f070aebb; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Content-type: text/html; charset=UTF-8

OK
(the code block not working is a known issue, which we aren't fixing because we plan to make some other changes to the Forums soon)
 

Benjamin D.

Well-Known Member
Jan 28, 2016
205
33
78
Canada
cPanel Access Level
Root Administrator
Hi! Thanks for trying to help me.

It instantly works and outputs "OK" when I execute it from the command line in bash with: /usr/bin/ea-php81 /home/xxx/public_html/session_start_test.php

But what does that mean though?
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
14,252
2,219
363
cPanel Access Level
Root Administrator
The trick with any troubleshooting is isolation - we want to see exactly what portion of the tool is broken. In this case, that test let us confirm the following:

-PHP 8.1 itself, is working
-your script is working and formatted properly
-permissions on the user account are setup properly

So those are all good things. Now...why doesn't Apache/PHP want to display the code of the website? I would run this command on the server while loading the site in the browser to see what Apache thinks:

Code:
tail -f /usr/local/apache/logs/error_log
as that will show any errors in real-time on the system. Hopefully that will provide a clue as to why it's not working in a browser.

If you have nginx installed on the server, it might be worth it to clear the cache to see if that changes the behavior.
 

Benjamin D.

Well-Known Member
Jan 28, 2016
205
33
78
Canada
cPanel Access Level
Root Administrator
As I wrote in the first post, there is nothing written to the local error_log (the one in that site's public_html folder) AND if I execute (the tail command) and then request the file with my browser, nothing pops up either.

I really don't understand why this works when this domain is set to PHP 7.4 in MultiPHP Manager but not when it's set to PHP 8.1. I have never seen that in 20 years, even under PHP 5.

I thought that perhaps it's the web browser on the computer that I'm using at the moment that's acting up, so I rebooted just to be sure. Same. I tried with my cellphone on the LTE network just to be 100% sure that it's not something that's bound to my current IP and nope, same thing.

If I toggle it back to PHP 7.4, there's no issue, it loads instantly.

BTW: No, I'm not using NGINX.
 

Benjamin D.

Well-Known Member
Jan 28, 2016
205
33
78
Canada
cPanel Access Level
Root Administrator
Over the last 2 hours I've been blocked here, I have experimented further and discovered something that may be relevant to the issue at hand:

If I restart Apache and restart my web browser, THE FIRST TIME I request that script, the session file is created and everything SEEMS TO WORK: It returns "OK" and the script stops loading, everything is normal and instantaneous. BUT all the subsequent requests to any PHP file that contains a session_start() it will hang on that session_start() line and I can see that the session file REMAINS OPENED even after I cancel the loading of the script in my web browser:

[[email protected] ea-php81]# lsof ./*
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
php-cgi 29472 yyyy 6uW REG 8,2 0 1445816 ./sess_609a290fe150721c44ecf54ac528bf5e

PHP 7.4 did not behave like that and I think this is culprit in PHP 8.1. I don't understand why after the script ended it doesn't unlock the session file, but if I request the simple test script in a PRIVATE TAB, then it works the first time I request it and hangs on all subsequent times. Then I close the private tab and re-open another private tab and I can reproduce the issue: The first time I request the script, it works, then all subsequent times it doesn't. I've read threads on other forums about session locking issues with PHP but I have yet to find what part of the configuration in WHM I have to change to make it behave like PHP 7.4
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
14,252
2,219
363
cPanel Access Level
Root Administrator
I'm not able to reproduce that part of the issue - the page loads for me, in any type of tab, no matter how many times I request it.

I've attached a copy of my PHP info page's "Session" section if you'd like to compare it to your server:

Screen Shot 2023-02-08 at 7.16.42 AM.png
 

Benjamin D.

Well-Known Member
Jan 28, 2016
205
33
78
Canada
cPanel Access Level
Root Administrator
After 6 hours of trying to troubleshoot this yesterday, I gave up and ran an EasyApache provision to install PHP 8.2 instead of 8.1 and it seems to work just fine, so I don't know what's up with the release of PHP 8.1 that my server had, but updating to 8.2 seems to do the trick. Plus, I read on PHP.NET that they fixed a bunch of session related bugs, so perhaps this had something to do with the issue I've experienced all night yesterday under 8.1. Thanks for trying to help me, but it's gonna be 8.2 from now on and I've completely removed 8.1 from EasyApache just to be sure no site uses it ;-)

We could close this thread. Thx again.