How to create socket connection with php?

How do i create several persistent socket connection TCP/IP to the same host using PHP

  • Currently my situation is i have a window server hosting web and will communicate to unix host server(database) to retrieve data whenever user request. I'm using apache and PHP for my window server. Can i actually create a new persistent socket connection to host whenever a new user log in and the socket will tie to the specific user? the socket should only tie with one user. The reason to use persistent socket is because allow user to continue the connection with other pages after the user log in for security purpose. However using persistent socket will only have on connection, if second user come in the user will continue use the existing connection. Second user shouldn't share the same with the 1st user. i have tried use fsockopen() but whenever go the other page it will start up a new connection and need to re-enter user and password at unix host side. Is there any way i can keep my server to unix connection stay connected for the same user? if the other user come in will require to login and tie the connection after successful login.

  • Answer:

    finally able to connect to the same host with multiple persistent socket by contain a "/" followed by a unique identifier <?php $identifier = "id1"; //unique identifier for every new persistent socket create $host = "tcp://mysql.example.com:33/" . $identifier; $socket = stream_socket_client($host, $errorno, $errorstr, $timeout, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT); ?>

santrekate at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

You need an assisting TCP service on your windows webserver machine, to maintain the connections to your mainframe. something like: http://www.dart.com/telnet-activex-tool-control.aspx

user247245

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.