One script hangs whole website

Summary

On one of my VPS I get strange behavior: script that using modX hangs whole website.

Step to reproduce

1 I create php file ‘test.php’ and call modx instance

require_once '/absolute/path/to/modx/config.core.php';
require_once MODX_CORE_PATH.'model/modx/modx.class.php';
$modx = new modX();
$modx->initialize('web');

and for test purpose call:
sleep(10);

2 I run test.php and all pages of website waiting 10 seconds until test.php completes.

This problem arise only on one of my VPS, on another is all fine. Could anyone please give me advice what configuration I should check?

Environment

MODX Revolution 2.7.2,
NGINX 1.14.0,
MySQL 5.7.35
location ~ .php$ {
try_files $uri @modx_rewrite;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}

If any single PHP script will cause your server to hang, that sounds like PHP-FPM may only have one process available?

If I don’t use modX, only leave line with sleep(10) - script doesn’t hang website

That’s weird, I’ve never seen anything like that and don’t really know how to explain what you’re seeing.

PHP’s sleep() actually idles the CPU so that shouldn’t be blocking anything, and the only other thing I can come up with is the database. Initializing the MODX class will connect to the database and that’ll usually stay open until the request is closed. Other requests for the site will then also try to connect to the database.

Again I’ve not actually seen anything like this before so I’m grasping at straws, but perhaps something on the database server is preventing more than one client connection at a time and the sleeping thread is causing that to halt?

I also consider more to db, but I have no idea what mysql setting can affect this

I tested hanging website in another browser - and all was fine. Problem with hanging was only with testing website in the same browser window.

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.