Reputation: 5413
I have a chatdemo.php which includes socket.php socket file. Inside the socket.php file there is a line
socket_bind($master, $address, $port);
where $address = "localhost"
and $port=1300
.
However, when I put onto the browser (and the apache from XAMPP is up) http://localhost/demo/chatdemo.php it says:
Warning: socket_bind() [function.socket-bind]: unable to bind address [48]:
Address already in use in /Applications/XAMPP/xamppfiles/htdocs/demo/socket.class.php on line 23
socket_bind() failed
So, instead, I goto the command line and did a
php -q /demo/chatbot.demo.php
Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for 'PDT/-7.0/DST' instead in /demo/socket.php on line 21
Server Started : 2012-03-27 17:24:24
Listening on : localhost port 13000
Master socket : Resource id #5
So the question is: Why can't I run that chatdemo.php on my browser on localhost(using XAMPP), whereas I could executed that on the command line using php(non-XAMPP)?
Upvotes: 3
Views: 3673
Reputation: 57650
You shouldn't even try to run a server (that listens to a port and accepts connection) by a web server. A web server, processes a request and invokes your PHP script as necessary. Your script has 30 seconds time to finish it. This is the expected behavior. But when you run a server. The story is different. It runs 24/7. Think about web server, it runs 24/7. Of course your server can have much less run time than this. But if you run it under a web server 1 of the thread will be blocked for long time for every request.
Servers should be run stand alone. In your case it should run from command line.
Farther reading.
For the warning at the command line just change the date.timezone
settings in php.ini
according to your location. I use
date.timezone = "Asia/Dhaka"
Upvotes: 1