I'm trying to run a PHP file from the cmd by entering the command "php index.php".
On my own pc, it doesn't work and I have no idea why, here is what happens:
What happens when I'm trying to run the file on my own PC.
While it works fine on my VPS which has the same files as my own pc has.
I made sure that they are both in the same folder with the 'websockets.php' file.
When I'm trying to run simple PHP file which prints "Hello World" with the CMD, it works,
but for some reason the socket next file doesn't work:
#! /usr/local/bin/php
<?php
require_once('websockets.php');
class echo_server extends WebSocketServer
{
//protected $maxBufferSize = 1048576; //1MB... overkill for an echo server, but potentially plausible for other applications.
protected function process ($user, $message)
{
if($message == 'help')
{
$reply = 'Following commands are available - date, hi';
}
else if($message == 'date')
{
$reply = "Current date is " . date('Y-m-d H:i:s');
}
else if($message == 'hi')
{
$reply = "Hello user. This is a websocket server.";
}
else if($message == 'lorem')
{
$reply = "4";
}
else
{
$reply = "Thank you for the message : $message";
}
$this->send($user, $reply);
//The uri component say /a/b/c
echo "Requested resource : " . $user->requestedResource . "n";
}
/**
This is run when socket connection is established. Send a greeting message
*/
protected function connected ($user)
{
//Send welcome message to user
$welcome_message = 'Hello. Welcome to the Websocket server. Type help to see what commands are available.';
$this->send($user, $welcome_message);
}
/**
This is where cleanup would go, in case the user had any sort of
open files or other objects associated with them. This runs after the socket
has been closed, so there is no need to clean up the socket itself here.
*/
protected function closed ($user)
{
echo "User closed connectionn";
}
}
$host = '0.0.0.0';
$port = 9000;
$server = new echo_server($host , $port );
$server->run();
?>
I think that the problem has no connection to the environment variable because as I said before, it works when I'm trying to run a simple php file.
It's also not a problem of the full path.
There are more ways to run this PHP file without the CMD?
I've tried to run it directly from the browser and it doesn't work :(
Some details that might help:
My own PC:
Windows 7, Runing PHP with zend server, apache 2, PHP Version: 5.6.18.
The VPS:
Windows Server 2008 R2, Runing PHP with zend server, apache 2, PHP Version: 5.6.18.
Thanks in advance.
</div>