Comments (7)
贴代码
from workerman.
这和workerman没有关系吧,直接global引有就行了,不过因为是全局变量,所以要考虑值的安全性
from workerman.
require_once 'conf/config.php';
$worker = new Worker();
//创建子进程的数目($markets是config里面的数组)
$worker->count = count($markets);
$worker->onWorkerStart = function ($worker) {
Timer::add(0.5, 'taskGenerator', array('worker' => $worker, 'markets' => $markets));
};
onWorkerStart里面的 $markets提示未定义
from workerman.
config.php
from workerman.
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就行了。
见php手册:http://php.net/manual/zh/language.variables.scope.php
from workerman.
嗯,使用global是可以。我还有另外一个问题:比如我有一个数组,数组里面的每一个元素我想用一个进程处理,workman要怎么实现啊?
from workerman.
hi, or use global variables:
require_once 'conf/config.php';
$worker = new Worker();
//创建子进程的数目($markets是config里面的数组)
$worker->count = count($markets);
$worker->onWorkerStart = function ($worker) {
Timer::add(0.5, 'taskGenerator', array('worker' => $worker, 'markets' => $GLOBALS['markets']));
};
kind regards, stefano
from workerman.
Related Issues (20)
- change worker after onMessage event HOT 3
- Question: What http workers do ? HOT 1
- How to start script many times at same time HOT 2
- Kill worker in linux HOT 4
- From Ratchet to Workerman HOT 1
- Error package because of receiving data before handshake HOT 3
- Restrict access by origin domain and limit the number of connections HOT 1
- Implementation of the onError() handler HOT 1
- Param sameSite in the $response->cookie() should be a string HOT 1
- v5版本使用swow发生文件不存在异常 HOT 3
- [BUG] 监听[::]22348地址,REMOTE_ADDR获取不到客户端ip HOT 1
- Run Workerman in daemon mode with Windows HOT 2
- Estrange behavior in composer require HOT 1
- runtime test HOT 2
- add a watch command
- ssl secure connection HOT 1
- Transferring data between workers HOT 5
- Timer::add in master process is impossible ? I think it can be HOT 1
- Use internal PHP to parse post data HOT 1
- Using this as Radius Server HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from workerman.