Jump to content

IPC functions running on Linux work, but fail on MacOS X


slipstream180

Recommended Posts

Hi All - I'm encountering a problem where I'm able to get the IPC message queue functions (msg_receive(), msg_send(), etc) working when running PHP on Ubuntu v9.04 Desktop, but on MacOS X v10.5.7 the msg_get_queue() function fails to retrieve the same message queue Resource across different PHP files.

 

Here is the test code I am using, which is taken from the "PHP Core Programming" book:

 

msg_server.php:

<?php
define ("SERVER_QUEUE", 1970);

define ("MSG_SHUTDOWN", 1);
define ("MSG_TOUPPER", 2);
define ("MSG_HELLO", 3);

$queue = msg_get_queue(SERVER_QUEUE);

$keepListening = true;
while($keepListening) {

  msg_receive($queue, 0, $type, 1024, $message, true, 0, $error);

  switch ($type) {

  case MSG_SHUTDOWN: 
    $keepListening = false;
    break;

  case MSG_HELLO:
    error_log($message . " says hello.\n", 0);
    break;

  case MSG_TOUPPER:
    $clientQueue = msg_get_queue($message['caller']);
    $response = strtoupper($message['text']);
    msg_send($clientQueue, MSG_TOUPPER, $response);
    if ($error != null)
      error_log("MSG_TOUPPER ERROR: $error\n", 0);
    break;

  } // end switch
} // end while

msg_remove_queue($queue);

?>

 

Then in a separate file, 'msg_client.php':

<?php
define ("SERVER_QUEUE", 1970);

define ("MSG_SHUTDOWN", 1);
define ("MSG_TOUPPER", 2);
define ("MSG_HELLO", 3);

$qid = rand(1, 10000);
$queue = msg_get_queue($qid);
$serverQueue = msg_get_queue(SERVER_QUEUE);

msg_send($serverQueue, MSG_HELLO, $qid);

msg_send($serverQueue, MSG_TOUPPER, array('caller' => $qid, 'text' => 'corephp'));

msg_receive($queue, 0, $type, 1024, $message);

msg_send($serverQueue, MSG_SHUTDOWN, NULL);

msg_remove_queue($queue);

?>

 

In this example, when running on Mac OS X, the server file never responds to the initial msg_send from msg_client.php. (Since the msg_get_queue() doesn't seem to access a common underlying queue for the "server". i.e. msg_get_queue(SERVER_QUEUE) returns a different resource in msg_client.php vs msg_server.php)

 

The MacOS X LAMP stack is configured with the following versions of software: Apache/2.0.59 (Unix) PHP/5.2.5 DAV/2 mod_ssl/2.0.59 OpenSSL/0.9.7l

 

The Ubuntu stack configuration:

Apache/2.2.11 (Ubuntu) PHP/5.2.6-Ubuntu4.1 with Suhosin-Patch mod_ssl/2.2.11 OpenSSL/0.9.8g

 

I don't know if this problem is a function of the underlying OS, or Apache, or something else...

 

We are using Ubuntu to serve our website, but we also use Mac OS X for development & prototyping, so we need identical functionality across platforms.

 

Thanks for any ideas in advance!

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.