• May 22, 2012, 10:41:19 PM
Welcome, Guest. Please login or register. Registration is free.
Did you miss your activation email?

Author Topic: PHP with TCP/UDP socket communications  (Read 364 times)

0 Members and 2 Guests are viewing this topic.

Offline Michael McNamara

  • Administrator
  • Hero Member
  • *****
  • Posts: 2517
    • Michael McNamara
PHP with TCP/UDP socket communications
« on: December 20, 2011, 11:59:52 PM »
Anyone using PHP for TCP/UDP socket communications?

I'm trying to write an interface engine to process data from a specific protocol feed.

I've been pretty successful in short time but I'm using the built-in PHP function fread to read data from the TCP socket. I set the socket timeout for 5 seconds, read some data and then go off and do some processing and then loop back around and try to read more data, rinse and repeat.

The problem is that fread stops reading the socket when it's reached it max buffer length (defaults to 8K).

I'm guessing I need to use socket_recv or something along those lines.
We've been helping network engineers, system administrators and technology professionals since June 2009.
If you've found this site useful or helpful, please help me spread the word. Link to us in your blog or homepage - Thanks!


Offline Michael McNamara

  • Administrator
  • Hero Member
  • *****
  • Posts: 2517
    • Michael McNamara
Re: PHP with TCP/UDP socket communications
« Reply #1 on: December 21, 2011, 01:52:04 AM »
It turns out there wasn't any issue with the fread function in PHP. I was getting disconnected (timed out) from the far end server because I was only listening to the traffic and wasn't generating anything. I had to code in a keepalive function to just send a small command once every 180 seconds.
We've been helping network engineers, system administrators and technology professionals since June 2009.
If you've found this site useful or helpful, please help me spread the word. Link to us in your blog or homepage - Thanks!