How to enable websocket in xampp server? I use windows 10.
I want to build a chat based on websocket and but I can't connect to the websocket.
I found this article
http://phppot.com/php/simple-php-chat-using-websocket/ but I don't understand how to connect php xampp to websocket.
Uncomment extension=php_sockets.dll in php.ini file to enable websockets in php.
Simple.
Go to the project folder and run the "php php-socket.php" command on the terminal and the websocket server will works.
Make sure that the php path is in the environment variables, or run with full php path: "c:/xampp/full_path_to_php/php php-socket.php".
After running the server, access index.php with your browser and the chat will works.
php-socket.php is a script that creates a websocket service, class.chathandler.php is a chat implementation on the server side and index.php is the client side.
Please, sorry for my English.
I tried get to run the example too, with the same error. Following solution is working:
download the example code and copy to your htdocs folder.
open two tabs in your Browser. 1. run the php-socket.php and let it load. 2. run the index.php in the 2nd tab and the example will work.
I made some changes and got it working because I already have a website running on XAMPP.
"php-socket.php" → Change line 3:
define('PORT',"8090");
to:
define('PORT',"1337");
"php-socket.php" → Change line 11:
socket_bind($socketResource, 0, PORT);
to:
socket_bind($socketResource, HOST_NAME, PORT);
"index.php" → Change line 25:
var websocket = new WebSocket("ws://localhost:8090/demo/php-socket.php");
to:
var websocket = new WebSocket("ws://localhost:1337/demo/php-socket.php");
Make a .bat file inside this demo folder:
#echo off
"C:\xampp\php\php.exe" -q "C:\xampp\htdocs\demo\php-socket.php"
Launch the .bat file, and keep the cmd open as this is the socket listener or server; as soon as you close it, the frontend will say "Connection Closed"
Related
I am working on a webapp made by someone else which uses Bottle routing. I want to create a simple login page which requires some PHP. If I return the PHP page as a static_file, any HTML will be executed but PHP won't, for obvious reasons. How should I serve the PHP file so that it is dynamic?
Not working:
#route('/login')
def serve():
return static_file('login.php', root='.')
In order to server PHP files, you need to have PHP installed on the web server. Additionally, the webserver needs to be configured to detect PHP files and execute them.
Serving PHP files from Python is kinda useless and not recommended.
I'd recommend you to take the time to translate this script from PHP to Python.
I wanted to do the same thing yesterday, but the answers I got to my question made it clear it was either impossible or extremely difficult. I came up with writing a small python program to run the PHP built in server. NOTE: PHP needs to be able to run from the command line for this to work.
#Import the os package so that this code can run commands
import os
#Get the port that the user wants to host on
port = str(input("What port would you like to host on?"))
#Add wanted port to the command that hosts the php server
cmd = "php -S localhost:" + port
#Actually run the command to host php server
os.system(cmd)
#Now the PHP server will take over until you
#use ctrl + C to quit hosting
Just remember that the port needs to be 4 numbers. When you host this, you can return any file from the folder you ran this code in by simply typing it in the browser. Example:
localhost:8080/login.php
Returns login.php (if it is there) on the localhost port that you asked for.
I've been following the steps at this link: https://github.com/opentok/learning-opentok-php, and I can't get past the first step because I don't understand what I have to do on this part:
The run-demo file starts the PHP CLI development server (requires PHP >= 5.4) on port 8080. If you want to run your server on another port, edit the file. Finally, start the server using the run-demo script.
And then when i actually run the run-demo script and follow the link: http://localhost:8080/session i get this message on screen "You must run composer install in the sample app directory", and if i try to run the composer it doesent run.
Need to start the (PHP)WebSocket on my Ubuntu server. its a working script at least on my PC (using WAMP server). Here is the code
<?PHP
include('php_web_socket.php')
$socket = new php_web_socket();
$socket->wsStartServer('127.0.0.1', 30001);
?>
I'm executing this php file by using the following command
php /var/www/html/server/index.php
But the WS connection never open.
For reference,
I'm using the following script http://www.sanwebe.com/2013/05/chat-using-websocket-php-socket
I was making a mistake. Look the IP 127.0.0.1 - Localhost
lets allow the remote connection from rest of the world and change it to 0.0.0.0 and problem resolved!
So I want to make a daemon.php file which can open a port on a give ip address and request data from client.php and with the browser to listen/read to earlier pipe (Would that be a problem for the security or not?).
I fount this funphp tutorial which seems to be good but is more like a cronjob, I found also function stream-socket-server but can handle only one request and then shuts down, and I really don't know where exactly to put listener.
You can use the PHP Built-In Server
Add PHP to your PATH environment variable
Start your server on a given port, ex: php -S localhost:8000 OR
Start with a router script, ex: php -S localhost:8000 rt.php
Now, just open your browser and type; localhost:8000
I have putty.exe on my desktop so if I will go to command prompt and then to C:\Documents and Settings\user\Desktop location and execute following command it will launch the Putty window of telnet connection to server specified:
putty.exe telnet://a.b.c.d/
I am trying to launch the putty to telnet to specific server using following but its not working for me:
<?php
$securecrt = "C:\\Documents and Settings\\user\\Desktop\\putty.exe telnet://a.b.c.d/ ";
exec($securecrt);
?>
If I try following then it launches the putty application but will have to provide the host name or IP to login:
<?php
$securecrt = "C:\\Documents and Settings\\user\\Desktop\\putty.exe ";
exec($securecrt);
?>
Not sure if I am missing something very basic, It will be great if someone can help with this.
Instead of using Putty, you could try to use PHP with fsock or use a class like http://www.geckotribe.com/php-telnet/
However, you can try the following using your current setup:
$securecrt = '"C:\Documents and Settings\user\Desktop\putty.exe" telnet://a.b.c.d/';