Git Product home page Git Product logo

Comments (7)

walkor avatar walkor commented on May 17, 2024

贴代码

from workerman.

hetao29 avatar hetao29 commented on May 17, 2024

这和workerman没有关系吧,直接global引有就行了,不过因为是全局变量,所以要考虑值的安全性

from workerman.

jackyxie avatar jackyxie commented on May 17, 2024
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.

jackyxie avatar jackyxie commented on May 17, 2024

config.php

from workerman.

walkor avatar walkor commented on May 17, 2024
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.

jackyxie avatar jackyxie commented on May 17, 2024

嗯,使用global是可以。我还有另外一个问题:比如我有一个数组,数组里面的每一个元素我想用一个进程处理,workman要怎么实现啊?

from workerman.

MINORITYmaN avatar MINORITYmaN commented on May 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.