How can I access socket through Openshift - php

I register in the Openshift.com and create a catridge. But when I need to deploy Mosquitto, a MQTT Server, which is accessed through tcp or ssl protocol, and I need visit from public IP.
Does Openshift just redirect http/https protocol through 80/443 port to 8080?
Is it possible to use socket communcation in Openshift?
I have created two applications in Openshift, one for push and the other for web deployment, and I stopped the apache service in order to let the mosquitto service listen to 8080. But only if I send post request in https protocol, It can access to the server for a while and disconnect.

I think this might point you in the right direction https://www.openshift.com/blogs/paas-websockets.

To save some readings from the readers, the steps involved in niharvey's answer:
Create a diy app in your openshift account.
Git checkout the code.
Add a websocket app of your own choice that would bind to $OPENSHIFT_DIY_IP:$OPENSHIFT_DIY_PORT.
Modify the action hooks for starting and stopping your app. Push the code.
From the client, connect to port 8000 for ws:// or 8443 for wss://, by your app url.
Just verified these steps do work as expected.

Related

How to setup and run a PHP WebSocket service on a cpanel-based shared hosting platform?

I have created a Chat application in Ratchet PHP. It runs fine on local machine using WAMP. I want it to setup on live server.
On my server I have:
PHP Support
SSH access
Port 9000, which is opened for OutBound connections.
Sub-domains
What I don't have:
No port for InBound connections.
No root access in SSH. Say I cannot see/edit iptables
I ran php server.php which gives success message about the server is started and listening at port 9000. But when a HTML page tries to connect it using ws://domain:9000 it runs into error-
Firefox can’t establish a connection to the server at
ws://domain.com:9000/
I googled a lot and it appears that what I need is a port for inbound connections.
But according to this answer the thing I need is PHP support for Ratchet to work on shared hostings. Can anyone explains what I really need and Is there any workaround If it's not availble in the list of things I have on my server.
Basically, No
It is not likely for a shared hosting environment (i.e. Apache with VirtualHost config, PHP, MySQL, and a CPanel interface) to support your websocket application.
For websocket to work, you need to either:
have a port dedicated to websocket in-bound connections; or
have a HTTP/HTTPS server that knows when to upgrade a connection and proxy pass to your websocket application.
The first route requires the server to allow in-bound connection to a certain port number. This is a potential security issue for the hosting provider and, thus, is unlikely for your vendor to grant you that.
The second route requires Apache server have with both mod_proxy and mod_proxy_wstunnel installed and enabled. It also require you to use ProxyPass config, which cannot be overridden by .htaccess configs at all.
So unless your hosting grants you the permission to touch the Apache main configuration (or would apply such change for you), you're pretty hopeless.
Suggestion
To run your own websocket service, you should think about using Virtual Private Server services such as Amazon EC2, DigitalOcean VPS.

Connecting to Docker Container Network from the Client Side

I have two containers, a php server serving a laravel application and a spring boot application running a websocket server. My architecture was to connect the two containers using Docker Networking and have the Laravel container port published to the outside. The laravel application is pretty much all front end, and on one page is a chat room using websocket. I tried to connect the chat room to the Spring Boot websocket container name (Docker network) but I feel like because this request is coming from the client this is not possible? I am using the container name (domain name) as a URL on the javascript file that is being served by the php server. Would the only way to make this work is publish the Spring Boot port as well on a public server and replace the websocket url with a public url?
Additional info like docker-compose or commands you are running would also be helpful.
But from what I see, the issue probably is that the requests are coming from the client which means that they can't access the actual service since it's not available publicly...
You should probably make that service available as well by mapping the necessary ports to your host machine or create some proxy server to pass the requests to the websocket

Openshift inter-gear communication

I'm developing an app at OpenShift which consists on a node.js gear and a php gear.
The node.js gear must communicate with the php one, so for now, in node.js i'm just doing a normal http request to the php gear.
But I read there is a routable IP to intercomunicate gears through port 8080 using HTTP (https://www.openshift.com/forums/openshift/intra-gear-instance-communications) but have no clue on how to get that IP.
I have looked at env vars but there is nothing and using the domain name or the loopback IP does not connect on port 8080.
Any idea on how to get that IP or what i'm missing?
Thanks.

Application tool to perform cross browser testing within localhost

I am in the middle of building a website which means it is not uploaded to a server yet. Is there any way I can perform cross browser testing from the localhost and not an actual hosted URL?
Either by running lots of browsers natively (some in a VM), or by using SSH tunnelling to a commercial service like browserling (http://browserling.com/).
Edit to elaborate a bit: An SSH tunnel (a reverse tunnel technically) between your localhost and a server allows you to forward certain ports on the remote host to ports on your localhost, over an encrypted SSH channel. This means the browsers running on browserling's servers can send packets down the tunnel, back to your localhost and your webserver there.
Install PHP on your local machine, this way you can run PHP scripts in command-line or browsers.
http://php.net/manual/en/install.php
Configure your webserver to listen on your network IP and access your website through IP address on your local network.
If it is apache webserver It would be configured using directive:
Listen IP:port
Example 1 (your adapter IP address):
Listen 192.168.1.10:80
Example 2 (global listening on all interfaces) - better for testing
Listen 0.0.0.0:80
Then just simply access your computer from other browsers on other platforms.
Sure. If you're able to configure your local network you could expose port 80 or 443 to the cloud by making changes to your routers firewall. This would make your application as available for testing locally as any on a remote host.
Let me know if your question is about which tools you could use, either as external services or locally installable.

Socket.IO integration with Apache2 for live update calendar

I'm trying to build a calendar with live update using Socket.IO Websocket. I managed to get the Socket.IO server running on port 8181 but my calendar.php is managed via apache on port 80.
What I'm looking to do is to use my calendar.php with apache and at the same time connect to my Socket.IO server on port 8181 (or bind it to port 80 with apache but that seem to be pretty complicated, I tried back proxy but didn't work) to receive updates when someone edited a event in the calendar. My events are stored in a SQL database.
So is there a way to use Socket.IO on port 8181 in a php page served by apache on port 80?
Thanks!
I'm not sure I understand your issue. Once the page is served by PHP on port 80, you would connect to your socket.io server on 8181 in the simplest set up.
And from then on you wouldn't need to interact with php again since you'd probably be sending messages to your socket.io server to process.
For load balancing socket.io, I think you can use HAProxy and I think LearnBoost has an alternative on Github also. I actually haven't gotten to this step with my app yet, so I can't give too much info here.
But yeah, your socket.io server should receive, process and send messages. You can also use redis for Pub/Sub if you have multiple instances of socket.io running.
There is a node module for an asynchronous MySQL driver that will allow you to interact with your Database directly. I'm using MongoDb in my app, so I've never used the MySQL modules.
I guess alternatively, you could use your PHP server as a web service and your socket.io server could interact with it, but I imagine it would be slow to do it like that.
Hopefully that clears things up. Seems like your set up will already work in a dev environment.

Categories