parallel
parallel copied to clipboard
Is parallel work with swoole ?
Try ti use pnly in main process - all ok. Try to use in secondary thread only - get error "async-io must be used in PHP CLI mode"
I check sapi_name() before error - and it still "cli"
<?php
use parallel\{Channel, Runtime, Future, Events, Events\Event, Events\Input};
$future = (new Runtime())->run
(
function()
{
echo php_sapi_name().PHP_EOL;
$function = function(){sleep(1);};
\Swoole\Coroutine::create($function);
echo "Finish";
}
);
sleep(3);
echo $future->value();
$future->cancel();
Error generate this swoole method https://github.com/swoole/swoole-src/blob/9a0c19815358801febd495ed4c8b423df930ea74/ext-src/swoole_event.cc#L219
And if i understand right varible what we in CLI mode assign in swoole here https://github.com/swoole/swoole-src/blob/9a0c19815358801febd495ed4c8b423df930ea74/ext-src/php_swoole.cc#L698C17-L698C20
- In Zend runtime function "PHP_MINIT_FUNCTION"
but if create any coroutime before create Runtime it is work inside the thread too....
<?php
use parallel\{Channel, Runtime, Future, Events, Events\Event, Events\Input};
$function = function(){sleep(1);};
\Swoole\Coroutine::create($function);
$future = (new Runtime())->run
(
function()
{
echo php_sapi_name().PHP_EOL;
$function = function(){sleep(1);};
\Swoole\Coroutine::create($function);
echo "Finish";
}
);
sleep(3);
echo $future->value();
$future->cancel();
Well as i see for use some function Swoole in Parallel you need call this function in main process (where you create Runtime classes).
But what about short-named function Swoole\Coroutine\run - it is never work in thread , but synonim global function "swoole_coroutine_create" work (ofcourse if it wal call in main process)
Well it is very stange things what Swoole not work in parallel thread "without dance with gitar"
If you can use parallel in swoole it will only be by accident.
Realistically, it appears as if the rest of the community have nothing to say about swoole, and I personally won't be testing there.
Sorry about that, but closing this issue now as there's no work for us to do here.
Wanted to add a late note: one of the niceties of Swoole is its built-in Websocket/HTTP/etc servers and clients. Sometimes I've found that coroutines alone don't provide full async with streaming and timers, whereas using a separate thread appears to provide better scheduling.