PHP code example of masakielastic / polling

1. Go to this page and download the library: Download masakielastic/polling library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

masakielastic / polling example snippets




declare(strict_types=1);

l\Event;
use Io\Poll\StreamPollHandle;

$context = new Context();
$stream = fopen('php://temp', 'r+');
fwrite($stream, "hello\n");
rewind($stream);

$watcher = $context->add(new StreamPollHandle($stream), [Event::Read], 'demo');
$ready = $context->wait(0, 1000);

foreach ($ready as $triggered) {
    var_dump($triggered->getData(), $triggered->getTriggeredEvents());
}
bash
php examples/basic_tcp_server.php
php examples/basic_tcp_client.php