I have implement rachet websocket with codeigniter and it's working fine in localhost. This is a main server.php that we need to run from terminal / cmd
require __DIR__ . "/../vendor/autoload.php";
use Chat\Chat;
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
$server = IoServer::factory(new HttpServer(new WsServer(new Chat)), 2000);
$server->run();
I run this file from cmd with following command
D:\wamp\www\my_project\api\application\third_party\Realtime\bin server.php
This command start socket and now any user access my site through browser then they are connect with socket and I can sent message to him. When I close terminal / cmd then socket close automatic.
Now my development is done and I upload all source on "openSuse" server. So my question is how I run above server.php file on live server ? (for example amazon ec2 OpenSuse server). because server don't have terminal / cmd.
Also this should run persistent so any time any user access my site they are connect to server and I will send him message.
I try many way but it's not working any how.
after installing haproxy i create confing file haproxy.cfg into /etc directory
In this file i have set
backend ws
server ws1 my_public_ip:2000
backend www
timeout server 30s
server www1 my_public_ip:80
Here port 2000 is websocket port and port 80 is my apache port
I also try with 127.0.0.1 but it gives following error
[ALERT] 293/101352 (2291) : Starting frontend public: cannot bind socket [0.0.0.0:80]
After skip this error i create supervisor.conf file in /etc/ directory and add rachet program as per your given link
Here in command i gave full path to server.php file
command = bash -c "ulimit -n 10000; exec /usr/bin/php /srv/www/htdocs/ci_chat/application/third_party/Realtime/bin/server.php"
But it gives me following error
Error: Another program is already listening on a port that one of our HTTP servers is configured to use. Shut this program down first before starting supervisord.
My apache run on port 80
pgsql run on 5432
Now i can not understand which service need to shutdown.
Related
Hello I'm newbie for symfony frame work.
currently using Symfony version 3.4.
I'm implementing websockets to my project using Gos Web Socket Bundle (https://github.com/GeniusesOfSymfony/WebSocketBundle) and documentation also.
after run this command
`php bin/console gos:websocket:server`
getting message like this.
`Failed to listen on "tcp://127.0.0.1:8080": An attempt was made to access a socket in a way forbidden by its access
permissions.`
in config.yml added this
`# Web Socket Configuration
gos_web_socket:
server:
port: 8080 #The port the socket server will listen on
host: 127.0.0.1 #The host ip to bind to`
If I changed port no 8080 to 80 I will get any error from command prompt but in browser it doesn't work. If I used 8080 websocket server is not running. Help me out! spent whole full day on this.
Without being a root (or via sudo) you are not allowed to listen to privileged ports (<1024).
As for the port 8080 check if there is another service already running on it:
lsof -i :8080
Have you tried selecting another port, for example, 8888?
Hope this helps...
I have installed redis packages on my AWS ubuntu server and everything is working fine from the command line.
I have run the below things from command line and it shows me correct response.
netstat -nlpt | grep 6379
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 23504/redis-server
so my redis server is running correctly on 6379 port also I have added this port on aws security group so firewall is also not blocking.
Also when I check my redis log it also seems to be fine. below is my log.
The server is now ready to accept connections on port 6379
But when I run the below code from my PHP and I get the below error.
$redis = new Redis();
$redis->connect('localhost');
$redis->set('param',999);
echo $redis->get('param');die;
Error I am getting...
The mcook.co.in page isn’t working
mcook.co.in is currently unable to handle this request.
HTTP ERROR 500
I have tried the below solution mentioned in stackoverflow.com but none of are working for me.
Redis - Connect to Remote Server.
EDIT:
I want to telnet into my web server on localhost, and request my php file from command line:
I have:
1) cd'd into the directory I want to serve, namely "/www" (hello.php is here)
2) run a server at directory www: python -m SimpleHTTPServer
3) telnet localhost 80
but "connection is refused". what am I doing wrong?
You're probably trying to connect to a wrong port. Check with netstat -lntp which port is your http server listening on. The process will be listed as python/pid_number.
If you're using Linux then try this:
$ telnet localhost 80
GET /hello.php
I have setup my wercker.yml file with the following step midway:
- script:
name: Serve application
code: php -S localhost:8000 >> /dev/null &
That appears to run, however, in another step when I try cURL to http://localhost:8000 I get the following:
curl: (7) Failed to connect to localhost port 8000: Connection refused
It does it for all ports, not just 8000. Has anyone else managed to get PHP's in built server working in wercker, or open any ports?
Assuming you're using the wercker CLI and trying to set up a development pipeline, you need to use wercker dev with the --publish 8000 argument. This will forward the traffic from your host on port 8000 to the container on port 8000.
Also, if you're using boot2docker, you can't specify localhost, since boot2docker spins up a VM that runs docker. In that case you'll need to use your boot2docker IP, which you can find by running the boot2docker ip command.
First thing, I could see out there has already solved questions around the problem.
PHP web socket unable to bind socket
Issue in setting the socket server
socket_bind(): unable to bind address [99] (Ubuntu on Amazon EC2)
and many other resources, all of them said that problem is in-used port or external IP,
etc.
But I could not get over it.
My server is running on CentOS 6.3 and using CPanel (it is the HP server https://www.hpcloud.com/).
The web socket demo source code what I get is on https://code.google.com/p/phpwebsocket/
My setting is
$master = WebSocket("127.0.0.1",4444); // even I tried with localhost, they worked same
Here is the step what I tried and the corresponding errors:
1/. I tried following commands to ensure a port which I was using is available to use
$ lsof|grep 4444
$ netstat -a -p -n
But I always got the error although this port 4444 is free
Warning: socket_bind(): unable to bind
address [98]: Address already in use in
/home/myapp/public_html/websocket/server.php on line 60
2/. The strange thing is when I checked the port 835 which was using by
crond 1621 root DEL REG 252,1 39835 /lib64/libpam.so.0.82.2.#prelink#.B1eyGx
atd 1633 root DEL REG 252,1 39835 /lib64/libpam.so.0.82.2.#prelink#.B1eyGx
The funny thing happened:
Then I ran the server.php on my terminal command shell
php /home/myapp/public_html/websocket/server.php
the error has gone, instead of it is
Server Started : 2013-08-16 03:19:54
Master socket : Resource id #4
Listening on : 127.0.0.1 port 835
I thought that it started working, but actually it did not, because when I open server.php by the browser with URL
http://mysite/server.php
The error is "permission denined"
Warning: socket_bind() [function.socket-bind]: unable to bind address
[13]: Permission denied in
/home/myapp/public_html/websocket/server.php on line 60
socket_bind() failed
Edited: About permission, I could open the client.html in same level directory with server.php without problem.
The folder code permission is 755 and user is not root.
All of my commands was implemented under root privilege
Any help is greatly appreciated :(
I would assume that the problem is that you are attempting to load the Websocket server in your webbrowser. Most likely, there are security settings for the apache user that does not allow your server to listen on uncommon ports.
CentOS usually ships with SELinux enabled by default. Part of CentOS Linux's security policies for Apache are that by default, Apache will only allow services access to recognized ports associated with HTTP (ie, port 80, 8080 etc).
With SELinux enabled, you could allow Apache to listen on tcp port 4444 by adding a rule to allow that inside SELinux using the 'semanage' command:
~$ semanage port -a -t http_port_t -p tcp 4444