Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is the example testwebsock.php multi threaded ? #124

Open
gfanini opened this issue Oct 25, 2019 · 1 comment
Open

is the example testwebsock.php multi threaded ? #124

gfanini opened this issue Oct 25, 2019 · 1 comment

Comments

@gfanini
Copy link

gfanini commented Oct 25, 2019

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

@ghedipunk
Copy link
Owner

ghedipunk commented Oct 25, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants