18739325251
您的当前位置:主页 > 知识博客 > Laravel开发 >

laravel4项目中使用beanstalkd队列报错

时间:2019-04-12

先放错误。

NULL.ERROR: exception 'Pheanstalk_Exception_ConnectionException' with message 'Socket error 60: Operation timed out (connecting to localhost:11300)'

项目中需要用到队列去异步处理耗时的任务,所以使用了laravel自带的queue功能。

原以为使用beanstalkd只需要配置config/queue.php中的项目就可以了,但是一直出错,连接不到beanstalkd,网上搜了很多东西都不能解决问题。

最后发现,还需要手动在服务器或者本地安装beanstalkd服务并启动,laravel框架只是提供了相应的驱动。

话不多说,贴出安装beanstalkd队列服务器的代码
mac: brew install beanstalkd
centos: yum install beanstalkd
ubuntu: sudo apt-get install beanstalkd

然后启动队列服务器
beanstalkd

重启beanstalkd服务
service beanstalkd restart

最后启动监听队列,在项目根目录下执行
php artisan queue:listen


大功告成

ps还需要修改php.ini配置 把proc_open,proc_status从disable中移除
~~~~~~~~~~~~~~~~~~~
原以为大功告成,但是这种情况下必须保持命令行窗口一直打开的状态,在服务器上显然不合适,所以还得使用supervisor监控beanstalkd队列
1、安装supervisor,推荐使用yum安装
yum install epel-release
yum install -y supervisor
systemctl enable supervisord //开机自启动
2、修改supervisord配置文件,以关联我们的beanstalk队列,配置文件应该位于ect/supervisord.conf
修改内容如下,其中command后面对应的是项目的目录
[program:xiaoka]
process_name=%(program_name)s_%(process_num)02d
command=php /www/wwwroot/xiaoka/artisan queue:work
autostart=true
autorestart=true
user=root
numprocs=8
redirect_stderr=true
stdout_logfile=/www/wwwroot/xiaoka/worker.log
3、启动supervisord服务
systemctl start supervisord
另附一些常用命令:
systemctl status supervisord //查看supervisord服务状态
ps -ef|grep supervisord //查看supervisord进程
systemctl stop supervisord
systemctl reload supervisord
systemctl restart supervisord

~~~~~~~~~~~~~~~~~~~~~~
其他疑难杂症
supervisord启动报错:
Starting supervisor: Error: Another program is already listening on a port that one of our HTTP servers is configured to use. Shut this program down first before staring supervisor

解决方法:

unlink /var/run/supervisor.sock
unlink
/tmp/supervisor.sock
两个都试一下

先放错误。 
NULL.ERROR: exception 'Pheanstalk_Exception_ConnectionException' with message 'Socket error 60: Operation timed out (connecting to localhost:11300)' 
项目中需要用到队列去异步处理耗时的任务,所以使用了laravel自带的queue功能。 
原以为使用beanstalkd只需要配置config/queue.php中的项目就可以了,但是一直出错,连接不到beanstalkd,网上搜了很多东西都不能解决问题。 
最后发现,还需要手动在服务器或者本地安装beanstalkd服务并启动,laravel框架只是提供了相应的驱动。 
话不多说,贴出安装beanstalkd队列服务器的代码
mac: brew install beanstalkd
centos: yum install beanstalkd
ubuntu: sudo apt-get install beanstalkd 
然后启动队列服务器
beanstalkd 
重启beanstalkd服务
service beanstalkd restart 
最后启动监听队列,在项目根目录下执行 php artisan queue:listen  
大功告成  
~~~~~~~~~~~~~~~~~~~
原以为大功告成,但是这种情况下必须保持命令行窗口一直打开的状态,在服务器上显然不合适,所以还得使用supervisor监控beanstalkd队列
1、安装supervisor,推荐使用yum安装 yum install epel-release yum install -y supervisor systemctl enable supervisord //开机自启动
2、修改supervisord配置文件,以关联我们的beanstalk队列,配置文件应该位于ect/supervisord.conf 修改内容如下,其中command后面对应的是项目的目录  
[program:xiaoka]
process_name=%(program_name)s_%(process_num)02d
command=php /www/wwwroot/xiaoka/artisan queue:work
autostart=true
autorestart=true
user=root
numprocs=8
redirect_stderr=true
stdout_logfile=/www/wwwroot/xiaoka/worker.log
 
3、启动supervisord服务
systemctl start supervisord 另附一些常用命令: systemctl status supervisord //查看supervisord服务状态 ps -ef|grep supervisord //查看supervisord进程 systemctl stop supervisord
systemctl reload supervisord
systemctl restart supervisord  ~~~~~~~~~~~~~~~~~~~~~~
其他疑难杂症
supervisord启动报错:
Starting supervisor: Error: Another program is already listening on a port that one of our HTTP servers is configured to use. Shut this program down first before staring supervisor

解决方法:
unlink /var/run/supervisor.sock
unlink /tmp/supervisor.sock
两个都试一下
 


技术支持:卓微网络科技 Copyright © 2015-2019 www.vrzytt.com 卓微科技 版权所有 豫ICP备16026818号-1