-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
主进程如何同子进程共享数据 #70
Labels
Comments
贴代码 |
这和workerman没有关系吧,直接global引有就行了,不过因为是全局变量,所以要考虑值的安全性 |
onWorkerStart里面的 $markets提示未定义 |
config.php |
require_once 'conf/config.php';
$worker = new Worker();
//创建子进程的数目($markets是config里面的数组)
$worker->count = count($markets);
$worker->onWorkerStart = function ($worker) {
global $markets;
Timer::add(0.5, 'taskGenerator', array('worker' => $worker, 'markets' => $markets));
}; 如jackyxie所说,加个global就行了。 |
嗯,使用global是可以。我还有另外一个问题:比如我有一个数组,数组里面的每一个元素我想用一个进程处理,workman要怎么实现啊? |
hi, or use global variables:
kind regards, stefano |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
使用过程中,发现onWorkerStart里面无法使用主进程中定义的常量。也无法直接在onWorkerStart里面引入文件定义的变量。有什么特定的引入方法吗?
The text was updated successfully, but these errors were encountered: