Jump to content

Keep socket connection alive between scripts


estero2002

Recommended Posts

Hi, I have this situation.

 

I'm writing a PHP site with several pages. Almost all of them need to connect to a server to get some data from it and show it to the client. This connections are made with sockets. Sockets are encapsulated in a class Socket, so, when a page loads, a new Socket object is is created. It connects to the server, gets the data and then, when the script finish executing, I understand PHP cleans the object and close the connection.

The problem is that I don't think is a good idea to be opening and closing connections every time a page is loaded. That is why I was wondering how to keep just one socket connection opened and use it from all pages. I know this can't be done with a session variable because resources can't be stored. Any other options? A global varialbe maybe?

 

Thanks in advance,

Steven

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.