Last active
September 22, 2016 03:53
-
-
Save ikariiin/6352895508572d3fa7b333eb5ed00ba0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php declare(strict_types = 1); | |
/** | |
* Created by PhpStorm. | |
* User: lelouch | |
* Date: 21/9/16 | |
* Time: 5:52 PM | |
*/ | |
//$pair = stream_socket_pair(AF_UNIX, SOL_SOCKET, 0); | |
$pair = stream_socket_pair(1, 1, 0); | |
list($parent, $child) = $pair; | |
class Stream extends Threaded { | |
public $stream; | |
public function __construct($stream) { | |
$this->stream = $stream; | |
} | |
} | |
class Child extends Thread { | |
private $stream; | |
public function __construct(Stream $stream) { | |
$this->stream = $stream; | |
} | |
public function run() { | |
$rawStream = $this->stream->stream; | |
fwrite($rawStream, "Huehuehue"); | |
fclose($rawStream); | |
} | |
} | |
class Server extends Thread { | |
private $stream; | |
public function __construct(Stream $stream) { | |
$this->stream = $stream; | |
} | |
public function run() { | |
$rawStream = $this->stream->stream; | |
$data = fread($rawStream, 4096 * 2 * 2); | |
if(strlen($data) > 0) { | |
var_dump("Date received: " . $data); | |
} | |
} | |
} | |
$child = new Stream($child); | |
$parent = new Stream($parent); | |
$ch = new Child($child); | |
$p = new Server($parent); | |
$p->start(); | |
$ch->start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment