Can PHP call a function and don't wait for it to return? So something like this:
function callback($pause, $arg) {
sleep($pause);
echo $arg, "\n";
}
header('Content-Type: text/plain');
fast_call_user_func_array('callback', array(3, 'three'));
fast_call_user_func_array('callback', array(2, 'two'));
fast_call_user_func_array('callback', array(1, 'one'));
çıkışı olur
one (after 1 second)
two (after 2 seconds)
three (after 3 seconds)
ziyade
three (after 3 seconds)
two (after 3 + 2 = 5 seconds)
one (after 3 + 2 + 1 = 6 seconds)
Ana betik kalıcı bir işlem (TCP sunucu) olarak çalıştırmak üzere tasarlanmıştır. callback() fonksiyonu, istemci veri almak harici PHP script çalıştırmak ve ardından callback() geçirilen diğer argümanlara dayalı olarak bir şeyler yapardı. Sorun dış PHP komut bitirmek için ana komut beklemek zorunda olmasıdır. Dış komut sonucu önemli olduğunu, bu nedenle exec('php -f file.php &') bir seçenek değildir.
Edit: Many have recommended to take a look at PCNTL, so it seems that such functionality can be achieved. PCNTL is not available in Windows, and I don't have an access to a Linux machine right now, so I can't test it, but if so many people have advised it, then it should do the trick :)
Teşekkürler, herkes!