posts with the tag: fork

Posted by: bob on Thursday July 28th 2011 1 comment
Tags: fork, queue

The next logical step in the development of our queue service is to allow the application to push itself into the background of a system and run detached from a terminal.

What is forking?

Forking is when you take one process, and clone it to create another with the same state as the original. When our application executes we will clone it, let the new copy take ownership of itself, and terminate the original. This leaves a background process or daemon running in the background still ready to process our queue.

PHP by default does not have the functions we need enabled. In order to enable them PHP will need to be compiled with the option –enable-pcntl. This will make the pcntl_* function set available to us.

Wanna fork?

Forking is a fairly simple process. The best time to fork is early on in the program, because when we do it literally everything about the application state gets copied over. This means file handles, database pointers, everything… and this usually causes problems. Fork before you open your files and databases, and you will find your life running much smoother.

Continue reading about forking our process

Posted by: bob on Tuesday July 26th 2011 no comments
Tags: daemon, fork, named pipe, queue

So to be hip, I am going to write one of these multipart blog things that describe building a simple project from start to finish. Are you ready? O.K. here we go.

What is a Queue Server?

A queue server is a server that processes a queue, which is why it is so aptly named. You send it a list of things to do and it does them over time based on your parameters, be it “as fast as possible” or “when system resources allow” or “once an hour” it is your call.

Over the course of the next week or so I am going to demonstrate building a simple queue server that will be able to fork itself off as a background daemon, accept input through a named pipe, and process things as fast as it can until it runs out of things to do – and when that happens it will sit there waiting with the upmost desire for you to provide it with more jobs.

Continue reading about this project…