PHP code example of iankuca / node

1. Go to this page and download the library: Download iankuca/node 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/ */

    

iankuca / node example snippets



echo "A";
setTimeout(function () {
  echo "C";
}, 2000);
echo "B";


$server = \Node\HTTP::createServer(function ($req, $res) {
  $res->writeHead(200, array(
    'content-type' => 'text/plain; charset=UTF-8'
  ));
  $res->write('Hello world!');
  $res->end();
});

$port = 8080;
$server->listen($port, 'localhost');
console_log('The HTTP server is listening on port %d.', $port);


$options = array(
  'host' => 'ifconfig.me',
  'path' => '/ip'
);

\Node\HTTP::request($options, function ($res) {
  console_log('status: %d', $res->status);
  print_r($res->headers);

  $res->on('data', function ($chunk) {
    echo $chunk;
  });
});


\Node\FS::readdir('/tmp', function ($err, $files) {
  if ($err) throw $err;
  print_r($files);
});