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?
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>
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>