我在symfony(2.4)项目中实现了Mmoreram gearman包。
我有一个网站,用户使行动和触发工作。
:
# Get Gearman and tell it to run in the background a 'job'
$id = $this->params['gearman']->doHighBackgroundJob('MYBundleServicesPublishWorker~publish',
json_encode($parameters)
);
和我有一个工人无限运行,并做作业(迭代:0)
我在后台从命令行运行一次:
nohup php /myproject/app/console gearman:worker:execute MYBundleServicesPublishWorker > /tmp/error_log.txt > /tmp/output_log.txt &
配置如下:
gearman:
# Bundles will parsed searching workers
bundles:
# Name of bundle
MyBundle:
# Bundle name
name: myBundle
# Bundle search can be enabled or disabled
active: true
# If any include is defined, Only these namespaces will be parsed
# Otherwise, full Bundle will be parsed
include:
- Services
- EventListener
# Namespaces this Bundle will ignore when parsing
ignore:
- DependencyInjection
- Resources
# default values
# All these values will be used if are not overwritten in Workers or jobs
defaults:
# Default method related with all jobs
# do // deprecated as of pecl/gearman 1.0.0. Use doNormal
# doNormal
# doBackground
# doHigh
# doHighBackground
# doLow
# doLowBackground
method: doNormal
# Default number of executions before job dies.
# If annotations defined, will be overwritten
# If empty, 0 is defined by default
iterations: 0
# execute callbacks after operations using Kernel events
callbacks: true
# Prefix in all jobs
# If empty name will not be modified
# Useful for rename jobs in different environments
job_prefix: null
# Autogenerate unique key in jobs/tasks if not set
# This key is unique given a Job name and a payload serialized
generate_unique_key: true
# Prepend namespace when callableName is built
# By default this variable is set as true
workers_name_prepend_namespace: true
# Server list where workers and clients will connect to
# Each server must contain host and port
# If annotations defined, will be full overwritten
#
# If servers empty, simple localhost server is defined by default
# If port empty, 4730 is defined by efault
servers:
localhost:
host: 127.0.0.1
port: 4730
doctrine_cache:
providers:
gearman_cache:
type: apc
namespace: doctrine_cache.ns.gearman
我的问题是当我运行app/console cache:clear
和之后的工作进入工人崩溃
它的抛出错误:
PHP警告:require_once (/myproject/app/缓存/dev/jms_diextra/理论/EntityManager_53a06fbf221b4.php):打开流失败:没有这样的文件或目录/myproject/app/cache/dev/appDevDebugProjectContainer.php on line 787
PHP致命错误:require_once(): Failed open required'//app/缓存/dev/myproject jms_diextra/理论/EntityManager_53a06fbf221b4.php"(include_path = ':/usr/share/php:/usr/share/梨’)/myproject/app/cache/dev/appDevDebugProjectContainer.php on line 787
我怎么能解决它,我试着改变学说束缓存类型:file_system/array/apc但它没有帮助
我怎样才能克服这个?我做错了什么?
Thanks in advance
我发现了问题,我在我的worker中有这一行:
$this->doctrine->resetEntityManager();
,
现在我只打开连接并关闭它,像:
$em = $this->doctrine->getEntityManager();
$em->getConnection()->connect();
# run publish command
............
# close connection
$em->getConnection()->close();