Php Symfony';s进程PID在执行期间增加1。。。?
我创建了一个Symfony命令,它将一些数据导出到文件中。每个用户的数据都是特定的,并且我的命令接收userID作为参数。如果未指定userID,该命令将查找所有用户,然后对其进行迭代,为每个用户调用相同的命令,但这次使用的是用户ID:Php Symfony';s进程PID在执行期间增加1。。。?,php,symfony,process,Php,Symfony,Process,我创建了一个Symfony命令,它将一些数据导出到文件中。每个用户的数据都是特定的,并且我的命令接收userID作为参数。如果未指定userID,该命令将查找所有用户,然后对其进行迭代,为每个用户调用相同的命令,但这次使用的是用户ID: // command execute(): $user = null; $userId = $input->getOption('userId'); if($userId !== null) $user = // find user by ID i
// command execute():
$user = null;
$userId = $input->getOption('userId');
if($userId !== null)
$user = // find user by ID in DB
if($user === null)
{
// create $command and other arguments
$users = // findAll()
foreach($users as $user)
{
// add user ID argument
$returnCode = $command->run($argumentsInput, $output);
}
}
else // do the export for specified user
或多或少,这就是它的工作原理。现在,我想从controller调用此命令作为后台进程:
// controller action:
$process = new Process($command); //without userId
$processId = $process->getPid();
// save PID to file
而且它几乎起作用了。几乎,因为PID改变了。我猜在某个地方开始了一个孩子的过程。就我所见,运行一个又一个命令的进程的实际PID是$processId+1
,尽管其他一切似乎都正常工作(一个进程调用命令,它们工作并导出数据),但没有一个进程使用$processId
。
我不会假设它总是
+1
,我只是想知道,为什么会发生…?这不是过程
应该做的吗?为每个命令运行一个新线程?@Stepashka我并不真正关心这里的“子”线程PID——我想知道,为什么运行“父”命令(并启动其他命令)的进程的PID与通过getPid()获得的PID不同……在alpine linux上,它似乎不需要+1