Some of my users have requested an addition to add a subscribe box to their blog pages so when they create a new blog post, their subscribers will be notified of the new blog post.
Prior to this, we had a Follow button. Following a page made an entry in the database with simply page_id and email. When a new post was created, an entry was created in a table containing what the email should say (New blog post by Mario, title, intro, link, etc...) and a cron job would run daily - compile all the new posts into 1 email and send it to everyone following the page.
I'm trying to find another way other then using a cron job.
How can I, during the posting a new blog post code execution - execute another PHP script and return from the blog post code without waiting for the subscription code to finish?
I think I'm looking for a thread but I've never used it before.
Any suggestions?
why not just execute it as shell command (using PHP CLI)?
<?php exec('php my-other-script.php > /dev/null 2>/dev/null &'); ?>
code untested; taken from SO and modified to fit your needs :)
threading is nice, you can take a look at the pcntl as well or you could use shmop to pass data between php processes.
for me this sounds like a classic view pipeline job. you add it to the queue which will be picked up from a worker running somewhere.
Emil Moe
Senior Data Engineer
Laravel has Queues. I think the princip is to have a FIFO stack table in the database and a cronjob running all the time on the stack.