PHP safelock failed to create a lockfile
-
This fixed it for me:
sudo usermod -a -G compiler username
0 -
I appreciate the reply Flyer. I've tried that but the issue remains
0 -
Did you log out and back in again? The group change doesn't take effect until you do that.
0 -
Yes, I have logged out and login in
0 -
Update:
I've just noticed that this only occurs when using popen() https://www.php.net/manual/en/function.popen.php
php:
php -v
PHP 8.3.19 (cli) (built: Mar 13 2025 00:00:00) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.19, Copyright (c) Zend Technologies
with Zend OPcache v8.3.19, Copyright (c), by Zend Technologiesdistro:
cat /etc/os-release
NAME="AlmaLinux"
VERSION="9.5 (Teal Serval)"
ID="almalinux"
ID_LIKE="rhel centos fedora"
VERSION_ID="9.5"
PLATFORM_ID="platform:el9"
PRETTY_NAME="AlmaLinux 9.5 (Teal Serval)"
ANSI_COLOR="0;34"
LOGO="fedora-logo-icon"
CPE_NAME="cpe:/o:almalinux:almalinux:9::baseos"
HOME_URL="https://almalinux.org/"
DOCUMENTATION_URL="https://wiki.almalinux.org/"
BUG_REPORT_URL="https://bugs.almalinux.org/"ALMALINUX_MANTISBT_PROJECT="AlmaLinux-9"
ALMALINUX_MANTISBT_PROJECT_VERSION="9.5"
REDHAT_SUPPORT_PRODUCT="AlmaLinux"
REDHAT_SUPPORT_PRODUCT_VERSION="9.5"
SUPPORT_END=2032-06-010 -
What specifically triggers that error - a restart of the Apache service?
0 -
This is all PHP CLI stuff (please don't judge my life decisions)
initialize_all.php
<?php
use Application\Config\DatabaseConfig;
use Application\Models\Repository\ClientRepository;
require_once 'vendor/autoload.php';
require_once 'cli/_cli_boot.php';
/**
* @var array $applicationConfig
*/
$options = getopt('e:f::', ['env:', 'force::']);
$env = '';
if (isset($options['e']) || isset($options['env'])) {
$env = $options['e'] ?? $options['env'];
}
if (strlen($env) === 0) {
print "Missing value for --env [proj|prod]\n";
exit;
} elseif (!in_array($env, ['proj', 'prod'])) {
print "Invalid environment value provided. Expected --env [proj|prod]\n";
exit;
}
$dbConnections = new DatabaseConfig($applicationConfig);
$clientList = (new ClientRepository($dbConnections))->getListForEnv($env);
$force = '';
if (isset($options['f']) || isset($options['force'])) {
$force = ' -f &> /dev/null';
$s = count($clientList) === 1 ? '' : 's';
print 'Force run for ' . count($clientList) . ' client' . $s . ".\n";
}
// TODO: better queueing system
$pipes = [];
foreach ($clientList as $client) {
$pipes[] = popen('php cli/client/initialize.php -e ' . $env . ' -c ' . $client->getCode() . $force, 'w');
}
foreach ($pipes as $pipe) {
pclose($pipe);
}Usually the cron runs this as `initalize_all.php` but when I pass the -f and run it manually I get all the safelock errors. I have to sed/grep them out of my logs when it runs on the cron otherwise log files get huge when this runs every 15 minutes
so, my solution to this safelock thing right now when running manually is piping to devnull:
$force = ' -f &> /dev/null';
0 -
What if you used pnctl_exec instead of popen?
Spoiler - I don't speak PHP so I reached out to a dev on this one.
0
Please sign in to leave a comment.
Comments
38 comments