Swoole过程永远悬而未决
我有最简单的吞咽代码,它可以睡一秒钟,并在屏幕上打印“运行任务”消息。
<?php
namespace Tests\Util;
use PHPUnit\Framework\TestCase;
class MultiprocessingTest extends TestCase
{
public function testProcess(): void
{
$t = new \Swoole\Process(function ($process) {
sleep(1);
echo "Run task\n";
}, false);
$t->start();
echo "Start main process!\n";
}
}
问题是它永远悬挂。但是,如果我删除睡眠(1),它将按预期运行并退出。那怎么了?
I have the simplest Swoole code, which sleeps for a second and prints "Run task" message to the screen.
<?php
namespace Tests\Util;
use PHPUnit\Framework\TestCase;
class MultiprocessingTest extends TestCase
{
public function testProcess(): void
{
$t = new \Swoole\Process(function ($process) {
sleep(1);
echo "Run task\n";
}, false);
$t->start();
echo "Start main process!\n";
}
}
The problem is that it hangs forever. But if I remove sleep(1), it runs and exits as expected. What is wrong with that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据Swoole文档,您应该使用
co :: Sleep()
而不是sleep()
swoole coroutine System:Sleep-sleep-sleep-正式文档
According the Swoole documentation, you should use
co::sleep()
instead ofsleep()
Swoole Coroutine System: sleep - Official documentation