Running PHP file in XAMPP versus php command line
I have a chatdemo.php that contains a socket file called socket.php. Inside socket.php file there is a line
socket_bind($master, $address, $port);
$address = "localhost"
However, when I put in a browser (and apache from XAMPP gets up) http: //localhost/demo/chatdemo.php it says:
Warning: socket_bind() [function.socket-bind]: unable to bind address : Address already in use in /Applications/XAMPP/xamppfiles/htdocs/demo/socket.class.php on line 23 socket_bind() failed
So, instead, I went to the command line and did
php -q /demo/chatbot.demo.php Warning: date(): It is not safe to rely on the system 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 this chatdemo.php in my browser on localhost (using XAMPP), then how could I accomplish this on the command line using php (non-XAMPP)?
source to share
You shouldn't even try to start the server (which listens on the port and accepts the connection) using the web server. The web server handles the request and calls your PHP script as needed. Your script has 30 seconds to finish it. This is expected behavior. But when you start the server. The story is different. It works around the clock and seven days a week. Think of a web server, it runs 24/7. Of course, your server can have much less uptime than that. But if you run it under a webserver, 1 of the thread will be blocked for a long time for every request.
The servers must work autonomously. In your case, it should be run from the command line.
To prevent the command line just change the settings
according with your location. I use
date.timezone = "Asia/Dhaka"
source to share