# __ .______ __ __ .______ .___________. ______ ______ .___ ___. # | | | _ \ | | | | | _ \ | | / | / __ \ | \/ | # | | | |_) | | |__| | | |_) | `---| |----` | ,----'| | | | | \ / | # | | | ___/ | __ | | ___/ | | | | | | | | | |\/| | # | | | | | | | | | | | | __ | `----.| `--' | | | | | # |__| | _| |__| |__| | _| |__| (__) \______| \______/ |__| |__| # ""$o o$"" ""$o o$" o "$""""o "o $" o""" $" "$o "$o" $o " $ o$" "$o $$$o$$$$o$$$$ $" "oooo o "" ""$$$$$$$$""o"" oo oooo" "$$$$$$oo"oo$$$o" o$$$$oo" o$$$o "o$$$$$$$ "$ $$$$$$$$$oo o$$$$$$$$$o"$" $ $$$ $$$$$$ o$$$$$$ "$$o"o $ $$$$o $$$$$$ $$$$$$$ $$$$o"o $ $$$$$ $$$$$" "$$$$$ $$$$$$ $ $o""""" """" """ """"""$" $ o$$$$$"""$$$$$"$$$$$""$$$$$ooo"o $ o"$o $$$$$$$$oo$$$$$$$$o $$"" $ oo$ "$$$$$$$$$$$$$$$$$$$$" o" o $oo o$$$"$ $$o"o $$$$$$$"" "$$$$$$$ o$$ $$$$o IPHPT BUG o$$$$" $ $$$$ o "$$$$$oo o$$$$$$ "o$$$$ $ $$$$$ o$$"" $ $$$$$o" "$$$$$$$$$$$$$ o o$$$$$o$ "" $$ $$" $ $$$" o"o$$$$$$$$$$$$ " "$$$ $ $$o o$$ "o $$ " $$$$$$$$$$$"o "$$ $ $$$ $$$ oo$ $ o""$$""$$$o " $"o$o $$$o o$$$$ o$$$"o"$oo$$$$o" o $o $$$$$oo$ $$$$o $$$$ $$$$ $$$$" $ $$$$$"" $$ o$$$ """$$$$"o" "$$$o "$$$o $$$" o """ $ $$$oo $$$$o" $$ o$$$"o" """"$ o$$$ o$" $$$ $ "$"" o$"o"$$o$$$$ "$$"o" o$$ "$oo $ " $$o $ "oo$"o$$$"o$o"$$$$o" o" $$$ ""$o $$ $$$o "o$$o$"$$"$$o$$o$$"$$o" $$$ ""o $$$ ""$$$ $$$$$$ $$$$ $" $$$$ $$ $$$$ $$$$"$$$o$ $"" $$$ $$$$ "$$$ """ $$$$ $$"" "$$ oo$" $ooo $ "$$ laravel 利用supervisord 监听队列发送邮件   -  叶落山城秋

laravel 利用supervisord 监听队列发送邮件

laravel邮件配置之前已经说了 地址:laravel 邮件发送

今天是因为研究phphub源码,验证用户的邮件!

发现用的好像是国内搜狐的 sendcloud , 于是我改成了自己的! 因为那个是收费的!

phphub源码 - app/Phphub/Handler/EmailHandler.php 里的 sendActivateMail方法

改成

    public function sendActivateMail(User $user)
    {
        UserVerification::generate($user);
        $token = $user->verification_token;

       return Mail::raw(url('verification', $user->verification_token).'?email='.urlencode($user->email), function (Message $m) use ($user,$token) {
            $m->to($user->email)->subject(lang('Please verify your email address'));
        });

然后其他的不动!

根目录执行 php artisan queue:listen 发现手机能收到邮件了!
但是 居然收到了二十几条!

然后看了下文档!说是用Supervisor

supervisor文档 我靠,都是英文,还那么多!

于是就google了其他方法!

先安装supervisor 执行命令(我deepin系统,基于debian,跟ubuntu差不多)

sudo apt-get install supervisor

安装完了,看到 /etc/supervisor/supervisor.conf 里的最后一行

[include] files = /etc/supervisor/conf.d/*.conf

然后直接在 conf.d 文件下新建一个sendMail.conf

[program:waaQueue]
command                 = php artisan queue:work
directory               = (此行是你的项目绝对路径)/data/wwwroot/myself/phphub5/
process_name            = %(program_name)s_%(process_num)s
numprocs                = 6
autostart               = true
autorestart             = true
stdout_logfile          = (修改为你要的log地址)/data/wwwroot/myself/phphub5/storage/logs/supervisor_waaQueue.log
stdout_logfile_maxbytes = 10MB
stderr_logfile          = (修改为你要的log地址)/data/wwwroot/myself/phphub5/storage/logs/supervisor_wqqQueue.log
stderr_logfile_maxbytes = 10MB

然后执行 supervisord

报错

Error: File contains no section headers.
file: /etc/supervisor/conf.d/sendMail.conf, line: 1
'aaQueue]\n'
For help, use /usr/bin/supervisord -h

发现是我的sengMail.conf第一行复制错了!

修改后再次执行

依然报错

Traceback (most recent call last):
  File "/usr/bin/supervisord", line 9, in <module>
    load_entry_point('supervisor==3.2.0', 'console_scripts', 'supervisord')()
  File "/usr/lib/python2.7/dist-packages/supervisor/supervisord.py", line 367, in main
    go(options)
  File "/usr/lib/python2.7/dist-packages/supervisor/supervisord.py", line 377, in go
    d.main()
  File "/usr/lib/python2.7/dist-packages/supervisor/supervisord.py", line 77, in main
    info_messages)
  File "/usr/lib/python2.7/dist-packages/supervisor/options.py", line 1388, in make_logger
    stdout = self.nodaemon,
  File "/usr/lib/python2.7/dist-packages/supervisor/loggers.py", line 346, in getLogger
    handlers.append(RotatingFileHandler(filename,'a',maxbytes,backups))
  File "/usr/lib/python2.7/dist-packages/supervisor/loggers.py", line 172, in __init__
    FileHandler.__init__(self, filename, mode)
  File "/usr/lib/python2.7/dist-packages/supervisor/loggers.py", line 98, in __init__
    self.stream = open(filename, mode)
IOError: [Errno 13] Permission denied: '/var/log/supervisor/supervisord.log'

恩!/var/log/supervisor/supervisord.log没有写权限,执行 sudo chmod -R 777 /var/log/supervisor/supervisord.log

再次执行 supervisord

还报错

Error: Cannot open an HTTP server: socket.error reported errno.EACCES (13)
For help, use /usr/bin/supervisord -h

/run没有权限

执行sudo chmod 777 /run

再执行supervisord

报了个这个Unlinking stale socket /var/run/supervisor.sock

我也不知道是不是错!

不过我手机收到邮件了!

我再次执行supervisord

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 starting supervisord.
For help, use /usr/bin/supervisord -h

说进程已经在执行了!

然后手机收到了邮件! 且!!!!!!只有一条!

点击邮件! 恩!本地用户邮件验证功能已修改好!

那么接下来是阿里云服务器里的!

同样的方法!我阿里云服务器是ubuntu14.04的

首先遇到

/usr/lib/python2.7/dist-packages/supervisor/options.py:295: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security.
  'Supervisord is running as root and it is searching '
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 starting supervisord.
For help, use /usr/bin/supervisord -h

不用担心,只是说用root执行的,等级有点高,要注意! 下面一行是说已经在运行了!就不要再次运行了!

但是我没收到邮件

执行supervisorctl status

发现

waaQueue:waaQueue_0              FATAL      can't find command 'php'
waaQueue:waaQueue_1              FATAL      can't find command 'php'
waaQueue:waaQueue_2              FATAL      can't find command 'php'
waaQueue:waaQueue_3              FATAL      can't find command 'php'
waaQueue:waaQueue_4              FATAL      can't find command 'php'
waaQueue:waaQueue_5              FATAL      can't find command 'php'

发现说找不到php命令

我执行export PATH=$PATH:/usr/local/php/bin php 命令不存在

再执行supervisorctl reload

就算我执行php -v 已经可以了!

但执行supervisorctl status 还是说php命令不存在

那就用绝对路径吧…

/etc/supervisor/conf.d/sendMail.conf里的第二行的command后面换成 /usr/local/php/bin/php 然后重启! 差不多了!

恩! 然后收到邮件了!


欢迎转载,但请附上原文地址哦,尊重原创,谢谢大家 本文地址: https://www.iphpt.com/detail/69/
本站(PHP --> Golang)已重构,代码开源

当你能力不能满足你的野心的时候,你就该沉下心来学习