Home > PHP Framework > Laravel > What is the difference between laravel event listening and job

What is the difference between laravel event listening and job

WBOY
Release: 2022-06-06 15:46:41
Original
2447 people have browsed it

Difference: 1. Event monitoring focuses on events that have been executed, while job focuses on events that are being executed; 2. Event monitoring is suitable for short-time operations, such as changing the status of data fields. , and job is suitable for long-term execution tasks, such as sending emails in batches.

What is the difference between laravel event listening and job

#The operating environment of this article: Windows 10 system, Laravel version 6, Dell G3 computer.

What is the difference between laravel event monitoring and job

Job

job is executed asynchronously. Suitable for long-term execution of tasks, suitable for long-term tasks. For example, send emails and text messages in batches.

The focus is on what is being dealt with. The operation is in progress...

If you want to delay the execution of an operation, or the process takes a while, 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 and each person as a job, and the service staff will help us handle the business one by one. After completing a business, the system will call the next person and execute the next job. Everyone needs to handle different business, and 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 be triggered. 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.

Event is executed within the life cycle of request.

Suitable for short-time operations. For example, changing data field status.

The focus is on events that have been executed. After the operation is completed...

In summary

Job focuses on what is being done:

Registering, updating, publishing, batch distribution

Things that Event focuses on and has done:

Registration completed, update completed, publishing completed, sending completed

They can be mixed and used, adding job tasks in the event .

[Related recommendations: laravel video tutorial]

The above is the detailed content of What is the difference between laravel event listening and job. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template