1

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.

santrekate
  • 31
  • 5
  • If your using a database connection you should really be using the dedicated driver for that database, otherwise I think you will need to use a new port for every connection. PHP is stateless, on its own, you should use a combination of cookies and session data to achieve a stateful process. – glend May 20 '15 at 07:54
  • This may be of interest: http://stackoverflow.com/questions/1086380/how-does-facebook-gmail-send-the-real-time-notification – Teson May 20 '15 at 08:04
  • i'm using "$fp = pfsockopen("tcp://171.21.211.55",21, $errno, $errstr, 10);" this to connect to unix server to retrieve data. inside unix server there are existing cobol programs to run and format data to send back the webserver. How can i specify new port using pfsockopen for every new user? Sorry, i'm very new in php. – santrekate May 20 '15 at 08:15
  • substitute 21 in your code. I'm no longer sure a new port is required per-user, In fact the telnet server probably wont allow it. Telnet should be able to handle multiple connections over the same port. – glend May 20 '15 at 08:18
  • The primary problem is that PHP is stateless, you can't really get around that. Not in the way you are describing, @user247245 has an interesting idea, i'm not sure that's what your looking for though. Can you think of any other way you could achieve the desired results? – glend May 20 '15 at 08:21
  • Thanks for reply. yup, it won't allow other port but 21. so far i can see there will be different port create for remote server when i connect with fsockopen. but there is no way to create a different remote server port with pfsockopen. or there is another way to keep the connection alive when go to other pages? – santrekate May 20 '15 at 08:34

2 Answers2

2

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
  • 31
  • 5
0

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

Teson
  • 6,644
  • 8
  • 46
  • 69