PHP code example of expressif / stream

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

    

expressif / stream example snippets



  xpressif\Stream\EventEmitter;

  class Foo extends EventEmitter {
    public function bar() {
      $this->emit('bar', ['baz']);
    }
  }

  $foo = new Foo();
  $foo->on('bar', function($what) {
    echo "Foo $what !\n";
  });
  $foo->bar();


  xpressif\Stream\Loop;
  Loop::setInterval(function() {
    echo 'Now is ' . date('H:i:s') . "\n";
  }, 1000);


  xpressif\Stream\Loop;

  $buffer = Loop::buffer('tcp://173.194.66.104:80');
  $buffer->read(function($response) {
    echo '<- ' . $response;
  });
  $buffer->on('write', function() {
    echo "-> Request sent\n";
  });
  $buffer->on('close', function() {
    echo "*** response is finished ***\n";
  });
  $buffer->write("GET / HTTP/1.0\r\nHost: www.google.com\r\n\r\n");