Here is the basic setup:
The PHP script writes to a table in the database, and then returns it NOTIFY job_added. Then he begins to listen to the answer, releasingLISTEN job_complete
The daemon (written in C) has already released LISTEN jod_addedand therefore wakes up and processes the table.
The daemon processes the table and writes the results to the result table before calling NOTIFY job_complete
The PHP script then wakes up and extracts the result from the result table.
All but the last step works. The daemon uses libpq, and I checked the success NOTIFYreleased by the daemon after adding the result to the result table.
So, I think the problem is with the PHP script. Here is a sample code:
$id = query("INSERT into jobs_table (/* details not important */) VALUES (/* */) RETURNING id");
query("NOTIFY job_added");
//daemon wakes up and does its thing.
query("LISTEN job_complete".$id);
$time = time();
while((time() - $time) < 30) {
$notify = pg_get_notify($conn);
if($notify) {
// Never gets here
if($notify['message']=="job_complete".$id) {
//our job has completed
break;
}
}
usleep(25000);
}
, , LISTEN 30 , , .
, pg_get_notify() NOTIFY, . : NOTIFY, , LISTEN PHP , .
-, , ? Btw, , query() , .