Jump to content

Using socat within php


bmsullivan
 Share

Recommended Posts

I've successfully been able to use:

both

shell_exec('socat -V')

and

system('socat -V')

 

My first question is:

Which one is better to use?  I've been reading the man pages on each, but can't tell if either is better.

 

Also, why is it that these commands will work, but if I want to use socat with an address and port to connect to it won't generate any output?  system('socat - TCP4:my.address:portnumber').

 

I'm working in Ubuntu and have the socat connection working fine in a shell, I'm just missing the php connection.

 

The server is working during the call, I've tried to flush() the php buffer and print out variables, but can't get anything. 

 

Wondering if I might need to connect to a socket via php and maybe that is why it won't work via the shell command?  If so, why?

 

Anyone have any insights on this? 

Link to comment
Share on other sites

system() returns only the last line of output, but shell_exec() returns the entire output.  And system() can optionally give you the return code of the command.  Based on my reading of the manual, those are the only differences.

 

I don't know about your second question.  Can you verify that the connection is being made (for example using a network sniffer or the server logs) and that output is being sent?  In theory, socat doesn't know it's being run under php so its behaviour shouldn't change.  But it MAY know that it's not connected to a terminal, and many programs change behaviour based on that.

Link to comment
Share on other sites

In theory, socat doesn't know it's being run under php so its behaviour shouldn't change.  But it MAY know that it's not connected to a terminal, and many programs change behaviour based on that.

 

Thanks, I'll look into the terminal thing you mentioned, that's at least a starting point as to where I can look.  If I discover anything else I'll post later on.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.