Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Message queues not working properly PHP -> C

14 views
Skip to first unread message

Muffinman

unread,
Nov 9, 2012, 4:05:49 PM11/9/12
to
Hello all,

I've got a php script that needs to send out some info to a c script
(already running). Somehow when php sends out through a message queue it
looks like it copies the previous message (send by php or c) and copies
it's own message over it with the previous message still visible if it
is longer than the next php message. No messages are lost though, only
copied and overwritten.

So see below the terminal output. First we send three time "Hi" (the
quotes are added by the c app). Then three time "Hai hai" and the last
time "Hi".

Adding \r, \n or \n\r does not help

Can someone tell me what's going wrong here? Communication between php
-> php goes without error, same goes for c -> c and c -> php. But php ->
c not.

The php script is copied below.

Thanks in advance, Maarten

key is 1107375495
spock: ready to receive messages, captain. msqid = 196612
spock: "Hi"
spock: "Hi"
spock: "Hi"
spock: "Hai hai"
spock: "Hai hai"
spock: "Hai hai"
spock: "Hii hai"

************************
<?php
$MSGKEY = ftok ('/Users/Maarten/test.test' , 'B') ;


$msg_id = msg_get_queue ($MSGKEY, 0666);
print_r ($msg_id);

if (!msg_send ($msg_id, 1, "Quit", false, true, $msg_err))
echo "Msg not sent because\n";
?>
*********************

M. Strobel

unread,
Nov 10, 2012, 11:57:08 AM11/10/12
to
Do a 'cat /proc/sys/fs/mqueue/msg_max', it shows 10 on my system. Maybe your queue is
full. See the manual on msg_get_queue().

/Str.

Muffinman

unread,
Nov 11, 2012, 9:41:27 AM11/11/12
to
On 10-11-12 17:57, M. Strobel wrote:

> Do a 'cat /proc/sys/fs/mqueue/msg_max', it shows 10 on my system. Maybe your queue is
> full. See the manual on msg_get_queue().

For me it shows 16384 so that should be fine. In addition, if I don't
empty the queue, I can see them piling up without an issue when I
execute the php script. Problem is it seems to copy the previous message
and tries to overwrite it, which it fails if the new string is shorter
than the previous one.

Maarten

Muffinman

unread,
Nov 11, 2012, 9:57:38 AM11/11/12
to
On 09-11-12 22:05, Muffinman wrote:
> Hello all,
>
> I've got a php script that needs to send out some info to a c script
> (already running). Somehow when php sends out through a message queue it
> looks like it copies the previous message (send by php or c) and copies
> it's own message over it with the previous message still visible if it
> is longer than the next php message. No messages are lost though, only
> copied and overwritten.

Actually when I set 'serialize' to 'true' it doesn't include the
previous message send. However, in c the messages comes with an addition
at the beginning and end of the string which is why I turned it off in
the first place ("s:2:" and ";"):

spock: "s:2:"Hi";"

This is preferable than some 'random' data, but ugly nonetheless.

Maarten

Jerry Stuckle

unread,
Nov 11, 2012, 2:01:59 PM11/11/12
to
Yes, that would be correct. When you enable serialize, PHP processes
the data through the serialize() function before sending it.

Now I've never tried sending between PHP and C, so I haven't seen your
problem. However, some questions:

1). What OS are you using (including version)?
2). Do you have all errors being displayed? Your php.ini file in your
test system should have:
error_reporting=E_ALL
display_errors=on
3). What does the code in you C program look like?
4). What compiler did you use for the C program?

I'm sure I can come up with more :) but this is a start.

Actually - I just thought of something else. PHP may not be adding the
ending null character. What happens if you send "Hi\0"?



--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstu...@attglobal.net
==================
0 new messages