进程服务端:
<?php
use Workerman\Worker;
use Workerman\Lib\Timer;
require_once './vendor/autoload.php';
$task_worker = new Worker('text://127.0.0.1:1122');
$task_worker->name = 'TaskWorker';
$task_worker->onMessage = function($connection, $task_data)
{
$connection->send($task_data);
};
Worker::runAll();
客户端:
use Workerman\Worker;
use Workerman\Lib\Timer;
require_once './vendor/autoload.php';
$task_worker = new Worker('text://127.0.0.1:1122');
$task_worker->name = 'TaskWorker';
$task_worker->onMessage = function($connection, $task_data)
{
$connection->send($task_data);
};
Worker::runAll();
报错信息:
# php task.php
PHP Fatal error: Call to a member function add() on null in /home/wwwroot/default/workerman/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 203
Fatal error: Call to a member function add() on null in /home/wwwroot/default/workerman/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 203
# php task.php
PHP Fatal error: Call to a member function add() on null in /home/wwwroot/default/workerman/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 203
Fatal error: Call to a member function add() on null in /home/wwwroot/default/workerman/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 203。
通过Terminal连接服务端是可以的。
这个是学习http://doc3.workerman.net/faq/async-task.html,稍作改动了下。
谢谢;
客户端和服务端代码一样?