FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Message queues not working properly PHP -> C
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Message queues not working properly PHP -> C [message #179582] Fri, 09 November 2012 21:05 Go to next message
Muffinman is currently offline  Muffinman
Messages: 3
Registered: November 2012
Karma: 0
Junior Member
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";
?>
*********************
Re: Message queues not working properly PHP -> C [message #179583 is a reply to message #179582] Sat, 10 November 2012 16:57 Go to previous messageGo to next message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
Am 09.11.2012 22:05, schrieb Muffinman:
> 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";
> ?>
> *********************
>

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.
Re: Message queues not working properly PHP -> C [message #179587 is a reply to message #179583] Sun, 11 November 2012 14:41 Go to previous messageGo to next message
Muffinman is currently offline  Muffinman
Messages: 3
Registered: November 2012
Karma: 0
Junior Member
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
Re: Message queues not working properly PHP -> C [message #179588 is a reply to message #179582] Sun, 11 November 2012 14:57 Go to previous messageGo to next message
Muffinman is currently offline  Muffinman
Messages: 3
Registered: November 2012
Karma: 0
Junior Member
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
Re: Message queues not working properly PHP -> C [message #179590 is a reply to message #179588] Sun, 11 November 2012 19:01 Go to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 11/11/2012 9:57 AM, Muffinman wrote:
> 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
>

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.
jstucklex(at)attglobal(dot)net
==================
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Using += assignment recursively on an array w/o notice
Next Topic: phpmyadmin export
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 21 17:17:31 GMT 2024

Total time taken to generate the page: 0.02324 seconds