public function handleRequest($request, $response, $connection) { $path = $this->getPath($request); $fullPath = $this->docroot . DIRECTORY_SEPARATOR . $path; echo "Loading static file: {$path}" . PHP_EOL; // if(isset($this->fileCache[$path])) { // echo "cache hit for: $path" . PHP_EOL; // $response->setBody($this->fileCache[$path]); // return $this->send($connection, $response); // } $fd = fopen($fullPath, "r"); /* @note LibEvent doesn't handle file reads asynchronously (non-blocking) */ stream_set_blocking($fd, 0); $stream = new Stream($fd, $this->loop); $this->buffer[$path] = ''; $stream->on('data', Partial\bind([$this, 'onData'], $path)); $stream->on('close', Partial\bind([$this, 'onClose'], $path, $response, $connection)); $stream->on('error', Partial\bind([$this, 'onError'], $path, $response, $connection)); }
<?php require __DIR__ . '/../vendor/autoload.php'; use React\Partial; $add = function ($a, $b) { return $a + $b; }; $addOne = Partial\bind($add, 1); echo sprintf("%s\n", $addOne(5)); // outputs 6
public function query($domain) { return $this->resolveWhoisServer($domain)->then(Partial\bind(array($this, 'queryWhoisServer'), $domain)); }