Use php-redis to send emails to all users. The amount of data is huge. What should the idea be?

WBOY
Release: 2016-09-22 08:56:47
Original
1347 people have browsed it

I’m a little confused right now.

In the PHP code, put all the arrays that need to request the interface into the redis storage,
Then use a loop to brpop the array out, but isn't this process all executed by the PHP code?

Doesn’t the entire process have to be disconnected after PHP times out?

Reply content:

I’m a little confused right now.

In the PHP code, put all the arrays that need to request the interface into the redis storage,
Then use a loop to brpop the array out, but isn't this process all executed by the PHP code?

Doesn’t the entire process have to be disconnected after PHP times out?

Start a php script and run it from the command line

Correct answer upstairs.
Let’s use an analogy like this. Redis is a data pool, both A and B can connect to it, where A is your current task, which is only responsible for writing to Redis, and B is another task (such as the command line method that Charles said to start an infinite loop script ) It is only responsible for querying/deleting email data in Redis.

Infinite loop script pseudo code:

<code>set_timelimit(0);//让这个PHP程序可以无限时的执行
while(true) {
    $row = $redisInstance->shiftGroup('Email');//所有要发送的邮件是一个数组的话,取出第一个
    if (empty($row)) {
        sleep(1);//休息1秒
        continue;
    }
    SendMail($row);
}</code>
Copy after login

You can use the Pub/Sub mechanism of Redis and use NodeJS to build a simple message queue.

<code>redis.subscribe('email','sms','push',function (err,count) {
   
});

redis.on('message',function (chan,msg) {
    //处理要发送的消息
});</code>
Copy after login
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