const http = require('http');
let i = 0;
http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
setTimeout(function() {
res.end('Response: ' + i++);
}, 1000);
}).listen(8080);
Event-driven, non-blocking I/O with PHP
$loop = React\EventLoop\Factory::create();
$i = 0;
$server = new React\Http\Server(function (Psr\Http\Message\ServerRequestInterface $request) {
return new React\Http\Response(
200,
array('Content-Type' => 'text/plain'),
"Response: " . $i++
);
});
$socket = new React\Socket\Server(8080, $loop);
$server->listen($socket);
$loop->run();
$loop = React\EventLoop\Factory::create();
$i = 0;
$server = new React\Http\Server(function (Psr\Http\Message\ServerRequestInterface $request) {
sleep(1);
return new React\Http\Response(
200,
array('Content-Type' => 'text/plain'),
"Response: " . $i++
);
});
$socket = new React\Socket\Server(8080, $loop);
$server->listen($socket);
$loop->run();
$pusher->trigger(
'my-channel',
'my-event',
array('message' => 'hello world')
);
var channel = pusher.subscribe('my-channel');
channel.bind('my-event', function(data) {
alert('Received my-event with message: ' + data.message);
});
<script src="https://js.pusher.com/4.1/pusher.min.js"></script>
<script>
Pusher.logToConsole = true; // for dev
var pusher = new Pusher('app_key', {
wsHost: 'localhost',
wsPort: 8080
});
var channel = pusher.subscribe('my-channel');
channel.bind('my-event', function(data) {
alert(data.message);
});
</script>
docker run -it --rm -p 8080:8080 edgurgel/poxa-automated
composer require pusher/pusher-php-server
require __DIR__ . '/vendor/autoload.php';
$pusher = new Pusher\Pusher(
'app_key',
'secret',
'app_id',
[],
'localhost',
8080
);
$data['message'] = 'hello world';
$pusher->trigger('my-channel', 'my-event', $data);
private-