bmsullivan Posted September 14, 2011 Share Posted September 14, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/247131-using-socat-within-php/ Share on other sites More sharing options...
btherl Posted September 14, 2011 Share Posted September 14, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/247131-using-socat-within-php/#findComment-1269377 Share on other sites More sharing options...
bmsullivan Posted September 15, 2011 Author Share Posted September 15, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/247131-using-socat-within-php/#findComment-1269594 Share on other sites More sharing options...
bmsullivan Posted September 20, 2011 Author Share Posted September 20, 2011 After some searching I'm finding that the best way is to just connect directly with the socket via php...that will be my next move! Quote Link to comment https://forums.phpfreaks.com/topic/247131-using-socat-within-php/#findComment-1270992 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.