문제

I am using Brian Moon's Gearman Manager that allows me, for example, to send worker's to background. The problem I'm facing is when I want to use a variable that was defined outside of function by using the global keyword:

$var = 200;

  function worker_execution($job, &$log) {

    global $var;
    echo "global is: ".$var."\n";

}

This code won't output 200 because the variable is NULL!?

Do you know why how to enable global scope in worker functions?

I assume the problem is that gearman manager doesn't include the worker file as is... It's reading it and goes directly into the "worker function", but still, there should be a solution to get access the variable outside of the scope of worker function?!

도움이 되었습니까?

해결책

Show the entire code. If you declare the variable after calling $worker->work() for example, it won't be executed, as work() goes into infinite loop. I'm sure there is no problem with the global variable in the worker's code.

다른 팁

just note, refer to https://groups.google.com/forum/#!topic/gearman/CNbuTshWfXA, use $GLOBALS will work.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top