I am making html5 game www.titansoftime.com
I use ratchet as a php websocket server solution. It works great! http://socketo.me/docs/push
I did some standalone tests using the php pthreads extension and saw some very interesting results. It really works and works well .. until the websites are in the mix.
Pthreads provide php multithreading capabilities (this really works, and it's awesome). http://php.net/manual/en/book.pthreads.php
This is what I do:
/src/server.php This is the file that starts the daemon.
<?php session_start(); use Ratchet\Server\IoServer; use Ratchet\WebSocket\WsServer; use MyApp\Pusher; require __DIR__ . '/../vendor/autoload.php'; require_once __DIR__ . '/../mysql.cls.php'; require_once __DIR__ . '/../game.cls.php'; require_once __DIR__ . '/../model.cls.php'; $mysql = new mysql; $game = new game; $loop = React\EventLoop\Factory::create(); $pusher = new MyApp\Pusher(); $loop->addPeriodicTimer(0.50, function() use($pusher){ $pusher->load(); }); $webSock = new React\Socket\Server($loop); if ($loop instanceof \React\EventLoop\LibEventLoop) { echo "\n HAS LibEvent"; } $webSock->listen(8080, '0.0.0.0');
It all works great.
/src/MyApp/Pusher.php This class passes data to all connected users.
<?php namespace MyApp; use Ratchet\ConnectionInterface; use Ratchet\MessageComponentInterface; class AsyncThread extends \Thread{ public $client; public function __construct($client){ $this->client = $client; } public function run(){
All this works fine until I create a thread inside the event loop.
Am I mistaken about this or is php multithreading and websockets incompatible?
multithreading pthreads php websocket ratchet
Hobbes
source share