Skip to content

Instantly share code, notes, and snippets.

@steverhoades
Created August 25, 2014 20:47
Show Gist options
  • Save steverhoades/c7d2528491418bd06bd5 to your computer and use it in GitHub Desktop.
Save steverhoades/c7d2528491418bd06bd5 to your computer and use it in GitHub Desktop.
Blocking test with Event extension
<?php
require __DIR__ . '/../vendor/autoload.php';
/** @var $loop \React\EventLoop\ExtEventLoop */
$cfg = new \EventConfig();
$cfg->requireFeatures(\EventConfig::FEATURE_FDS);
$loop = new \React\EventLoop\ExtEventLoop($cfg);
$dir = getcwd();
$fd = fopen($dir . DIRECTORY_SEPARATOR . 'largefile', "r");
stream_set_blocking($fd, 0);
$stream = new \React\Stream\Stream($fd, $loop);
$stream->on('data', function() { echo 'large file read'. PHP_EOL; });
$loop->addPeriodicTimer(0.01, function() { echo "Timer". PHP_EOL; });
$loop->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment