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.
#The operating environment of this article: Windows 10 system, Laravel version 6, Dell G3 computer.
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!