简体   繁体   中英

PHP: Can I do anything else while reading a socket?

I have a PHP script that reads a socket open to an IRC server.

However I have some other things I would like to run independently, not just when a message is received from the IRC server. Is there any way to do this with PHP?

For example, this doesn't work

while (true) {
    while ($raw = fgets($socket)) {
        // message received
    }
    do_something_every_loop();
}

I could run another PHP script to do these checks, but could I then connect to IRC with the same account?

If that's CLI script you could try multithreading

http://php.net/manual/en/intro.pthreads.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM