0

I have a Win32 application server that communicates with its clients through its own protocol over TCP. I need to call some functions of this app server from PHP.

I open a socket, establish communication with the server, write a request to the socket, receive an answer, and close the socket. To get better performance I want to make a pool of connections to the app server.

How do I make a pool of connections (pool of sockets) in PHP?

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
host6
  • 1
  • 1
  • Possibly a duplicate of: http://stackoverflow.com/questions/908108/is-there-a-way-to-share-object-between-php-pages – leftclickben Feb 03 '13 at 15:46
  • 1
    I don't think you can set up a pool of connections in PHP. The interpreter is going to close the socket at the end of handling each request. It's something you'd have to implement in an extension. I would test to see if the repeated handshakes are large enough of a burden to justify the effort. – cleong Feb 03 '13 at 16:37

1 Answers1

0

You can open a socket with php to communicate with your server!

<?php
  $fp = fsockopen("udp://127.0.0.1", 13, $errno, $errstr);
  if (!$fp) {
      echo "ERROR: $errno - $errstr<br />\n";
  } else {
      // Write to a socket
      fwrite($fp, "Hello my server");

      // Read from socket
      echo fread($fp, 26);

      // Close the socket
      fclose($fp);
  }
?>
Maxiking1011
  • 97
  • 1
  • 2
  • 10
  • 2
    I'm sure this answer contains true statements, but does it actually answer the question? The question asks about *connection pools*. – Rob Kennedy Feb 03 '13 at 20:22
  • Thanks to all. I'm going to make simple solution: create socket, work with socket and close socket from PHP on client side and make a pool of threads serving socket connections on server side. – host6 Feb 04 '13 at 18:43