Currently, a php script is used to execute an external interface request to send an email, and then wait for the email to return, get the processing result, and then send the result to your database record .. It's too slow to process about entries in an hour .. The boss said that the thread pool should be used for the job. now, I am overwhelmed .. Not familiar with this... currently, a php script is used to execute an external interface request to send an email, wait for the email to return, get the processing result, and then send the result to your database record ..
It's too slow to process about entries in an hour ..
The boss said that the thread pool should be used for the job. now, I am overwhelmed .. I don't quite understand the specific practices. can you tell me the rough process? Is Thread extension used?
Reply content:
Currently, a php script is used to execute an external interface request to send an email, and then wait for the email to return, get the processing result, and then send the result to your database record ..
It's too slow to process about entries in an hour ..
The boss said that the thread pool should be used for the job. now, I am overwhelmed .. I don't quite understand the specific practices. can you tell me the rough process? Is Thread extension used?
If you have done something similar, you can give some comments.
2 w/h ≈ 5.55 QPS, indeed not high.
If your boss thinks that the execution of a single-threaded script is slow, there will be a few more. What you need is the pthreads extension (multithreading), or you can directly start multiple processes for processing (pcntl extension or even directly exec ).
However, from the perspective of your needs, the main content that occupies the processing time is the external IO wait. You can consider sending multiple emails (such as multi_curl) concurrently, sending emails asynchronously (such as curl's async), or using an asynchronous service (such as swoole extension) as a whole)
Add a field process_id to the data table.
When inserting database records, the value of mt_rand () is assigned to process_id at random)
Enable 10 PHP scripts,
The first script processes records whose process_id is 1: select * from send_email_list where process_id = 1 and status = 0
The second script processes records whose process_id is 2: select * from send_email_list where process_id = 2 and status = 0
In this way, 10 processes are processed at the same time, which is the simplest and most direct way to increase the processing speed by 10 times.
Multithreading, multi_curl concurrency, and swoole asynchronization are all feasible solutions. However, the above scheme can be implemented only by making simple changes on the existing basis, which may be more suitable for the subject.
Use nodejs as the background email sending service