Search code examples
phpsocketsdaemon

php socket with loop in server


I have installed easyphp in my local machine with windows 7. I am trying to develop a simple chat application using php socket as the server and AJAX as the client. The problem is that for the server to be running all the time you must have infinite loop in the php code. And when I try to open the server page in the browser it give response time problem. Later I knew that I should be using something like command line or telnet. Now my question is that how can I use these comman line or telnet to run the php server all the time? Thank you.


Solution

  • For a PHP daemon (or permanent running script) you will need to install a local webserver like wamp (www.wampserver.com) or xamp. Additionally php was never meant to be used as daemons, nevertheless you can find plenty of resources on "running a php daemon on windows 7". Try going for that.

    The core of your issue is to set your machine to call on a script, this can either be done through commandline (+r then type cmd and press enter, visit the path of your php script and execute it with php php daemon.php, also see this link - http://php.net/manual/en/install.windows.commandline.php).

    Once it works, you can cron it for that you can use this link: Running a PHP app on windows - daemon or cron?