Heim >Backend-Entwicklung >PHP-Tutorial >强制PHP命令行脚本单进程运行的方法_PHP教程
if (!empty($last_pid))
{
$command = exec("/bin/ps -p $last_pid -o command=");
if ($command == $processName)
{
return false;
}
}
}
$cur_pid = posix_getpid();
if ($fp = @fopen($pidFile, "wb"))
{
fputs($fp, $cur_pid);
ftruncate($fp, strlen($cur_pid));
fclose($fp);
return true;
}
else
{
return false;
}
}
/**
* 获取当前进程对应的Command
*
* @return string 命令及其参数
*/
function getCurrentCommand()
{
$pid = posix_getpid();
$command = exec("/bin/ps -p $pid -o command=");
return $command;
}
使用方法: