为什么我的Laravel 5.2事件在本地工作时无法在生产中工作? [英] Why don't my Laravel 5.2 events work on production when they work locally?

查看:81
本文介绍了为什么我的Laravel 5.2事件在本地工作时无法在生产中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在本地,我的Laravel 5.2项目运行良好,包括使用Redis排队的事件.

Locally, my Laravel 5.2 project works well, including events that are queued using Redis.

重要更新:后来我发现此前提不正确(并且我的事件不使用Redis),因此我不小心以误导性的方式发布了此问题.我希望我的长期荒谬的奋斗努力以及下面的回答将对其他也是活动新手的人有所帮助.

IMPORTANT UPDATE: I later discovered that this premise was incorrect (and my events don't use Redis), and so I'd accidentally posted this question in a misleading way. I hope my ridiculously long struggle and my answer below will be helpful to someone else who is an events newbie too.

但是我已经将我的项目部署到了​​生产服务器(我正在使用Laradock Docker安装程序).

But I've deployed my project to a production server (where I'm using a Laradock Docker setup).

在生产中,Redis用于缓存和延迟作业的分发.

There, on production, Redis works for caching and for delayed dispatching of jobs.

所以我知道我的Redis设置很好.

So I know that my Redis setup is good.

但是事件不起作用(即使当我的项目在本地计算机上时它们也起作用).

But events don't work (even though they worked when my project was on my local computer).

我的问题不是 Laravel 5.2事件未触发的重复项生产,因为我没有使用广播,而是因为我 am 使用了Laradock.

My question is not a duplicate of Laravel 5.2 event not firing in production because I'm not using broadcasting and because I am using Laradock.

我也已经尝试过这些命令(在docker exec -it laradock_workspace_1 bash的容器内部):

I've also already tried these commands (inside the container at docker exec -it laradock_workspace_1 bash):

php artisan config:cache
php artisan clear-compiled
php artisan optimize
composer install --no-dev
composer dumpautoload
php artisan queue:restart

推荐答案

我的事件现在正在生产中.这是我学到的:

My events are working on production now. Here is what I learned:

  1. 我将阅读 https://laravel.com/docs/5.2/events 很多次,但是我不知道为什么/为什么事件"(对我来说是个新概念)依赖Redis或cron工作. 因此,我上面的问题的全部前提是错误的!我没有使用Illuminate\Contracts\Queue\ShouldQueue,所以所有内容都是同步的,应该比我想的要简单得多.

  1. I'd read https://laravel.com/docs/5.2/events many times, but I don't know where/why I got the idea that "events" (which were a new concept to me) relied on Redis or cron jobs. So the entire premise of my question above was wrong! I was not using Illuminate\Contracts\Queue\ShouldQueue, so everything was synchronous and should have been more straightforward than I was thinking.

我认为关于composer dumpautoloadphp artisan clear-compiled此提示很有帮助(针对每次生产中的文件).

I think this tip about composer dumpautoload and php artisan clear-compiled was helpful (for after each edit of files on production).

主要问题似乎是我的某个数据库表似乎具有带有怪异值的记录,并且这些记录正在由事件检查,而这一切都在中断.

The main issue seemed to be that a certain database table of mine seemed to have records with weird values, and those records were being checked by the event, and that's where it was all breaking.

  • 我认为这些记录可能已进入损坏状态,因为在生产中,我认为部署后我不会立即启动cronjobs和worker.
  • 我的本地环境正在工作,因为它的表没有这些损坏的记录.

希望我的天真和误导性的问题(这导致了这场荒谬的长期斗争和这个答案)也将对其他活动新手有所帮助.

这篇关于为什么我的Laravel 5.2事件在本地工作时无法在生产中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆