Skip to content

server request and channel consumer #4481

Answered by matyhtf
mrceperka asked this question in Q&A
Discussion options

You must be logged in to vote

This is incorrect usage. The $consumer should be used in the Workerstart callback.

<?php declare(strict_types = 1);

use Swoole\Coroutine\Channel;
use Swoole\Http\Request;
use Swoole\Http\Response;
use Swoole\Http\Server;

\Co::set(['hook_flags' => SWOOLE_HOOK_TCP]);

// channel stuff
$channel = new Channel(1000);
$consumer = function () use ($channel) {
	echo "consume start\n";
	while (true) {
		
		$data[] = $channel->pop();
		var_dump($data);
	}
};

// SERVER
$host = '0.0.0.0';
$port = 9502;
$workers = 24;
$server = new Server($host, $port);
$server->set(
	[
		'worker_num' => $workers,
		'log_level'  => SWOOLE_LOG_WARNING,
	]
);

$server->on(
	"Start",
	function (Server $server) use ($host

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@mrceperka
Comment options

@mrceperka
Comment options

@matyhtf
Comment options

Answer selected by mrceperka
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants