本文整理汇总了PHP中swoole_event_add函数的典型用法代码示例。如果您正苦于以下问题:PHP swoole_event_add函数的具体用法?PHP swoole_event_add怎么用?PHP swoole_event_add使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了swoole_event_add函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _start
/**
* @brief 子进程进入控制调度
*/
protected function _start()
{
swoole_event_add($this->_worker->pipe, function ($pipe) {
$package = $this->_worker->read();
$this->_stats($package);
});
}
示例2: start
/**
* @brief 启动子进程
* @param \swoole_process $worker
*/
public function start(\swoole_process $worker)
{
$this->_worker = $worker;
swoole_event_add($worker->pipe, function ($pipe) use($worker) {
echo $worker->read() . PHP_EOL;
});
$this->worker();
}
示例3: _initPipeEvents
protected function _initPipeEvents($process, $workerType)
{
\Daemon\Library\Ipc\Shared::setCurrentTaskTable($process->pid, array('taskNum' => 0, 'workerType' => $workerType));
$objMaster = \Daemon\Process\Master::getInstance();
swoole_event_add($process->pipe, function ($pipe) use($process, $objMaster) {
$objMaster->dispatch($process);
});
}
示例4: init
function init()
{
$this->serv->on('WorkerStart', function (\swoole_server $serv, $worker_id) {
//每1分钟向服务器上报
$serv->tick(60000, [$this, 'onTimer']);
swoole_event_add($this->centerSocket->sock, [$this, 'onPacket']);
});
$this->log(__CLASS__ . '-' . self::VERSION . ' is running.');
}
示例5: __construct
public function __construct()
{
$this->process = new swoole_process(array($this, 'run'), false, true);
//$this->process->daemon(true,true);
$this->process->start();
swoole_event_add($this->process->pipe, function ($pipe) {
$data = $this->process->read();
echo "RECV: " . $data . PHP_EOL;
});
}
示例6: createConnection
/**
* create mysql connection
*/
protected function createConnection()
{
$config = $this->config;
$db = new \mysqli();
$db->connect($config['host'], $config['user'], $config['password'], $config['database'], $config['port']);
$db_sock = swoole_get_mysqli_sock($db);
swoole_event_add($db_sock, array($this, 'onSQLReady'));
$this->idle_pool[] = array('object' => $db, 'socket' => $db_sock);
$this->connection_num++;
}
示例7: onConnect
public function onConnect($client)
{
fwrite(STDOUT, "Enter Msg:");
swoole_event_add(STDIN, function ($fp) {
global $client;
fwrite(STDOUT, "Enter Msg:");
$msg = trim(fgets(STDIN));
$client->send($msg);
});
}
示例8: onStart
function onStart($serv)
{
$this->serv = $serv;
for ($i = 0; $i < $this->pool_size; $i++) {
$db = new mysqli();
$db->connect('172.16.1.19', 'test', 'test', '1188test');
$db_sock = swoole_get_mysqli_sock($db);
swoole_event_add($db_sock, array($this, 'onSQLReady'));
$this->idle_pool[] = array('mysqli' => $db, 'db_sock' => $db_sock, 'fd' => 0);
}
echo "Server: start.Swoole version is [" . SWOOLE_VERSION . "]\n";
}
示例9: task_run
public function task_run($worker)
{
swoole_event_add($worker->pipe, function ($pipe) use($worker) {
$data = $worker->read();
var_dump($worker->pid . ": " . $data);
if ($data == 'exit') {
$worker->exit();
exit;
}
sleep(5);
$worker->write("" . $worker->pid);
});
}
示例10: callback_function
function callback_function(swoole_process $worker)
{
$GLOBALS['worker'] = $worker;
swoole_event_add($worker->pipe, function ($pipe) {
$worker = $GLOBALS['worker'];
$recv = $worker->read();
if ($recv) {
$data = call_user_func_array('dosomething', [json_decode($recv, true)]);
$worker->write($data);
} else {
$worker->write('');
}
});
}
示例11: onConnect
public function onConnect($cli)
{
fwrite(STDOUT, "Enter your name: ");
$msg = trim(fgets(STDIN));
$data = json_encode(array('json' => 'Chat', 'ctrl' => 'Chat', 'method' => 'online', 'name' => $msg));
$data = pack("Na*", strlen($data), $data);
$cli->send($data);
swoole_event_add(STDIN, function ($fp) {
global $cli;
$msg = trim(fgets(STDIN));
$data = json_encode(array('json' => 'Chat', 'ctrl' => 'Chat', 'method' => 'send', 'sendto' => $this->channel, 'msg' => $msg));
$data = pack("Na*", strlen($data), $data);
$cli->send($data);
});
}
示例12: callback_function_async
function callback_function_async(swoole_process $worker)
{
echo "Worker: start. PID=" . $worker->pid . "\n";
//recv data from master
$GLOBALS['worker'] = $worker;
swoole_event_add($worker->pipe, function ($pipe) {
$worker = $GLOBALS['worker'];
$recv = $worker->read();
echo "From Master: {$recv}\n";
//send data to master
$worker->write("hello master\n");
sleep(5);
$worker->exit(0);
});
}
示例13: child_async
function child_async(swoole_process $worker)
{
//echo "Worker: start. PID=".$worker->pid."\n";
//recv data from master
$GLOBALS['worker'] = $worker;
global $argv;
$worker->name("{$argv[0]}: worker");
swoole_process::signal(SIGTERM, function ($signal_num) use($worker) {
echo "signal call = {$signal_num}, #{$worker->pid}\n";
});
swoole_event_add($worker->pipe, function ($pipe) use($worker) {
$recv = $worker->read();
echo "From Master: {$recv}\n";
$worker->write("hello master\n");
});
}
示例14: __construct
public function __construct()
{
$fp = stream_socket_client("tcp://127.0.0.1:9504", $code, $msg, 3);
$http_request = "GET /index.html HTTP/1.1\r\n\r\n";
fwrite($fp, $http_request);
swoole_event_add($fp, function ($fp) {
echo fread($fp, 8192);
swoole_event_del($fp);
fclose($fp);
});
swoole_timer_after(2000, function () {
echo "2000ms timeout\n";
});
swoole_timer_tick(1000, function () {
echo "1000ms interval\n";
});
}
示例15: onStart
public function onStart($server)
{
$pro_vs = $this->process;
$server = $this->server;
$application_vm = $this->application;
swoole_event_add($pro_vs->pipe, function ($pipe) use($pro_vs, $server, $application_vm) {
$str = $pro_vs->read();
ob_start();
$application_vm->execute(array('swoole_socket', 'getfd'), 'vmstat');
$result = ob_get_contents();
ob_end_clean();
$result_fd = json_decode($result, true);
foreach ($result_fd as $id => $fd) {
$server->push($fd, $str);
}
});
}