I have Ubuntu running XAMPP (the lamp stack: Linux, Apache, MySQL, PHP, Pear). I would like to use PHP and Beanstalkd together to make a simple queue that when a user goes on page1.php, a JOB is sent to the QUEUE for a WORKER to capture. The JOB would be an SQL statement that the WORKER would then execute:
What I have done so far is:
Installed Beanstalkd:
sudo apt-get install beanstalkd
Developed php code and the "job" that has to be done in page1.php. The job would be to send the sql statement
$sql
to the queue for the workers to execute (in future versions the job will be much more complex hence the queue system will be even more important).:
page1.php:
if (isset($_SESSION['authenticated']))
{
//if the user is logged in, send an sql statement to the queue
$user_id = $_SESSION['id'];
$sql = "UPDATE user_table SET count = count + 1 WHERE id = {$user_id}";
//... missing code that would send the statement
}
?>
- Developed the actions that have to be done by the WORKER.
WORKER:
<?php
$stmt = $conn->query($sql);//simple update
?>
PROBLEM / QUESTION:
The problem is I don't know what functions to call that create a worker, what function to call to send the queue. I have searched online various examples, but there are no complete ones and with very vague explanations. I have seen that something called pheanstalkd exists, which I read was a wrapper for beanstalkd and a lot of people are using it online, but I'm not sure if this is a requirement or not. Can anyone guide me into the right direction with what functions I need to call or what codes I need to execute in the linux terminal just to get this one example working? All feedback is very much appreciated and would help me not loose any more hair this week.