Coder Social home page Coder Social logo

stream's Introduction

Streams with libevent

Evented streams wrapper (used by expressif/http and expressif/cluster)

Requirements

  • php 5.6+
  • libevent 0.1.0

Installation

Get the libevent library from pecl : http://php.net/manual/fr/libevent.installation.php

Note : For windows you can download libraries from here : https://github.com/expressif/win-dist

Add this lib as a dependency composer require expressif/stream

Usage

EventEmitter

This class handles callback listeners and events emission :

<?php
  require 'vendor/autoload.php';
  use Expressif\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();

Timers

This helper provides a way to periodically executes specified code :

<?php
  require 'vendor/autoload.php';
  use Expressif\Stream\Loop;
  Loop::setInterval(function() {
    echo 'Now is ' . date('H:i:s') . "\n";
  }, 1000);

Buffers

This class handles buffered reads and writes :

<?php
  require 'vendor/autoload.php';
  use Expressif\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");

stream's People

Contributors

ichiriac avatar

Stargazers

 avatar

Watchers

grzchr15 avatar  avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.