Home  >  Article  >  PHP Framework  >  Analysis of jobs and events in laravel framework

Analysis of jobs and events in laravel framework

不言
不言Original
2018-08-25 17:29:503041browse

The content of this article is about the analysis of jobs and events in the laravel framework. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

When I was working on a project, I always had doubts about Job and Event. It feels like the two are the same thing, but I can’t figure out what the difference is! After a period of pondering and searching for relevant information, I made some summaries of Job and Event for easy memory.

Job

Job can be used both synchronously and asynchronously.
If you want to delay performing an operation, or the process takes a while, then you can choose to use Job, such as uploading a relatively large file.
Job is generally used for things that are being processed. For example, when we go to the bank to handle business, many people are waiting in line. We can regard the queue as a queue queue and each person as a Job, and the service staff will help us Handle business one after another. After completing a business, the system will call the next person and execute the next Job. The business that everyone needs to handle is different. This is the task that each Job needs to complete.

Event

Event listening can allow different roles to participate. Event listening can be thought of as a Job when a specific event occurs. Once the event is created, the listener will fire. Events can be understood as "when...", "just...". An event can be monitored by multiple listeners. For example, after logging in, the system needs to send both emails and text messages. At this time, a login event can be created. After the event is triggered, colleagues will be monitored for sending emails and text messages.

Job can be executed without interruption, similar to how we want to execute a script in the early morning every night.

In summary

JobFollow what you are doing:

  • Registering

  • Updating

  • Publishing

  • Batch release

EventWhat you have followed and done:

  • Registration completed

  • Update completed

  • Release Complete

  • Send Complete

Event is more used for things that have been completed, similar to English Past tense

Related recommendations:

In-depth analysis of event operations in PHP's Laravel framework, laravelevent

Laravel 5 Introduction to framework learning routes, controllers and views, laravel framework

The above is the detailed content of Analysis of jobs and events in laravel framework. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn