I had already a an issue when someone reached the basket on last 2023/03/29, it was a different PHP error which crashed the server. I had to manually restart the php service. Not enough memory:
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /var/www/mywebsite/prod/basket/basket_global.inc.php on line 956
So I added some memory to PHP and since yesterday I had no server crash (Nginx / PHP 8.1 / MySQL)!
memory_limit = 256M
Yesterday I had another crash of the server for which I just had to manually restart the php service:
systemctl restart php8.1-fpm.service
And once again, it happened just after someone went to the basket:
access.log:
185.230.yyyy.xxx - - [27/May/2023:02:15:09 +0000] "GET /us/basket HTTP/1.1" 200 10466 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.133 Safari/534.16"
error.log
2023/05/27 02:15:09 [error] 3221563#3221563: *18311176 upstream timed out (110: Unknown error) while reading response header from upstream, client: 185.230.yyyy.xxxx, server: mywebsite.com, request: "GET /us/basket/ HTTP/1.1", upstream: "fastcgi://unix:/run/php/php8.1-fpm.sock", host: "mywebsite.com"
And then only upstream timed out (110: Unknown error)
errors on the log file!
It happens randomly and not often, so I think it's because of this function from the basket part with an infinite while loop to generate unique working code:
function get_newMerchantReference() {
global $config, $dataBase;
while(1) {
$merchantReference = mt_rand(100, 999).'-'.mt_rand(100, 999).'-'.mt_rand(100, 999);
$sql = $dataBase->prepare('SELECT count(*) AS num
FROM oo__basket_infos_hext
WHERE merchant_reference LIKE :reference');
$sql->execute(array('reference' => $merchantReference));
$countUniqueId = $sql->fetch();
$sql->closeCursor();
$sql = $dataBase->prepare('SELECT count(*) AS num
FROM oo__order_infos_hext
WHERE merchant_reference LIKE :reference');
$sql->execute(array('reference' => $merchantReference));
$countUniqueId2 = $sql->fetch();
$sql->closeCursor();
if($countUniqueId['num'] == 0 && $countUniqueId2['num'] == 0) { break; }
}
return $merchantReference;
}
Can this while(1)
loop go wrong in a random way and cause the PHP service to crash?
How to modify it to generate random number like 213-126-323 which have not been already used and is stored in oo__basket_infos_hext
and oo__order_infos_hext
?
Aucun commentaire:
Enregistrer un commentaire