Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Building PHP Daemons and Long Running Processes

There are things you don't want to, or can't do, inside a web request. It could be a task that needs to be retired if it fails, maybe one that takes a significantly long time to process, or multiple jobs that need to be processed over time.
by

Tim Lytle

on 15 November 2017

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Building PHP Daemons and Long Running Processes

Long Running
and
PHP Daemons
Processes
Building stuff PhoneBurner
Retired Contract Developer
Tim Lytle - @tjlytle
Why? Time.
Things that take time.
Things that happen over time.
Processing files. Reports. Migrations. Batch inserts.
Queue processing. Real-time data. Workers.
How?
Don't exit.
Stop
eventually.
shouldn't stop.
Probably
//setup things

while($run){
//do some things
sleep(1);
}

//shutdown things
Restart.
(and if it's needed)
For Example:
Twitter Streaming API
You probably
shouldn't
Easy on
Stop
upstart
systemd
supervisord
fork
Daemons
Ubuntu.
Use at least
Respond to
pcntl_signal()
declare()
pcntl_signal_dispatch()
Control
one of these.
start on runlevel [2345]

respawn
respawn limit 5 60

setuid vagrant
chdir /vagrant/cli
exec php twitter.php
Alternatives
webhooks • platforms
Abstract
the setup.
Perhaps better
than queues.
(lets see some real code)
In case you only recognize people by their profile pics.
Queues
CRON might
work.
must be
Or that
successful.
And things
like them.
(or Debian)
a daemon.
Runs as
gearman
beanstalkd
rabbitmq
SQS/SNS
blocking
reservations
streaming
a while.
Okay for
Like a queue
without jobs.
it's done.
Retry until
responsibly.
1
3
2
do this.
signals.
this book.
You could buy
Database
Page URL
Keywords
Links
Last Update
Queue
Multiple Workers
Reasonable Timeout
Worker(n)
Fetch Page
Extract Keywords
Extract Links
Upsert Data
Seed
Select Stale URLs
Add as Jobs
Wait A While
Web
Crawler
Queue
Multiple Channels
Worker
Fetch User Data
Generate Content
Send Email
Web App
Create New User
Add ID as Job
For Two Channels
Email
Queue
Publish
Transcode
Thumbnail
Keyword
Publish
Check If Ready
Queue Up Work
Delay Job
Publish File
Thumbnail
Check if Done
Extract Frames
Queue Publish
Process
Transcode
Check If Done
Convert File
Queue Thumbnail
Queue Keyword
Keyword
Check if Done
Extract Keywords
Queue Publish
of a foreach loop.
Use next() instead
Track what
was done.
Just your
bootstrap.
Wait for the
next job.
Process a post,
send an email,
parse a log.
Long running
process is done.
Daemon should
restart.
Full transcript