Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7652099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:40:41+00:00 2026-05-31T11:40:41+00:00

I want to start using websockets to make a connection to a PHP socket

  • 0

I want to start using websockets to make a connection to a PHP socket server. This server should check at a certain interval if something has changed in the database and it should then send the changes back to the client. So when a client is connected, the connection should remain open aslong as the client (the webbrowser in this case) is on the page.

Then the server should check at a certain interval the database and send data back when needed. I know that the problem isn’t the websockets (except that not all major browsers support it yet). Mainly my concern is PHP. I want to create the server in PHP, but can i keep a connection open to a PHP code for aslong as i want?

And how about the interval. Normally in a C#.NET exe application i would just create a timer. How could this be done in PHP??

If this is all possible, can i just simply run my PHP code in an Apache webserver?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:40:42+00:00Added an answer on May 31, 2026 at 11:40 am

    Typically if you were to write a socket server in PHP, you would want to run it via a command line. The things you would want to take into consideration are:

    You need access to the sockets, which typically you don’t on a shared server, so you would have to go get yourself a VPS.

    You would want to set up a file on your server that would automatically start your PHP script every time the server is rebooted. Typically this is done by placing a shell script that runs the PHP script in /etc/init.d and then place a symlink to the shell script in /etc/rc5.d (assuming that’s your default level).

    You would also most likely not want/need Apache running, unless you also plan to use this server as a file server. If you are using it solely for a socket server, youw ould want to install PHP-CLI. This will save you memory.

    If you are trying to have real time interactions between users connected to your server, you may not want to involve a database at all. Your socket server will have a list of all subscribers connected to the socket server, so when one of them sends you a message, you can immediately send that message back out to all connected subscribers without storing anything in a slow database. Alternatively, you would want to keep info in memory if you can afford it.

    There is a solution for sockets not being supported on all browsers called socket.io. Basically I believe it tries to set up a browser websocket if it’s supported, but if it is not supported, it starts a Flash socket connection. Either way you use the same interface to interact with it.

    You also may want to consider another language for creating your socket server. PHP isn’t really built for this type of thing. A better language to use would be Javascript, especially if scalability is a concern. Node.js is a library that would allow you to build a socket server quite easily, and would be much more scalable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to start using memcache with PHP (on Ubuntu 9.10). There are lots
So, I want to start using virtualenv this year. I like the no-site-packages option,
I want to start using Eclipse with the PyDev plugin, as recommended by this
I want to start using gettext to handle my translations on web projects (PHP
I want to start using OAuth to call my web server apis. Preferably I
I want to start using GitHub Pages for my project's website. This simply requires
I want to start using Python for small projects but the fact that a
I want to start using .NET 3.5 features in an app that is currently
I want to start using Nunit (finally), I am using Visual Studio 2008. Is
I want to start using Bing for a project which will include working out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.