Skip to content

is the example testwebsock.php multi threaded ? #124

@gfanini

Description

@gfanini

is the example testwebsock.php multi threaded ?
you need the pthread posix dll for php on windows in order to enable threads ?

I don't think so because it should have
extends Thread
client->start()
client->join() to wait for thread exit if needed

such as this pthread example


<?php
/*
* Please don't use resources, it's dangerous ...
*/
class Test extends Thread {
	public $stop = false;
	
	public function __construct($socket){
		$this->socket = $socket;
	}
	
	public function run(){
		while(++$clients < 10 &&
			($client = socket_accept($this->socket))){
			printf("Accept in %lu\n", $this->getThreadId());
			var_dump($client);
			var_dump($this->socket);
			socket_close($client);
		}
	}
}
$workers = array();
$sock = socket_create_listen($argv[1]);
if ($sock) {	
	while(++$worker<5){
		$workers[$worker] = new Test($sock);
		$workers[$worker]->start();
	}
	printf("%d threads waiting on port %d\n", count($workers), $argv[1]);
}

foreach ($workers as $thread)
    $thread->join();
?>

possibily could you post a multi thread version of testwebsock.php please

I think that example is single threaded, and handles receive in process() for each user, round robin, I enclose an example where also the transmit in tick() is called round robin for each user with per client requested data from a mongo db in case you wish to make a similar multiple client example please

www.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions