Socket.IO integration with Apache2 for live update calendar - php

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.

Related

PHP and node.js on the same server

I am using PHP for the backend of my website and I am introducing a node.js chat. I have everything figured out as far as authentication between the two, and my only problem now is switching between port numbers. How is this handled? Ideally I'd like to hide the port number and I've tried virtual hosts for this, but no matter how I configure the virutal host the server does not load and appears to be down. I am using cloudflare if this matter. But hiding the port isn't required. I just want to smoothly link to the chat app on port 2053 from the PHP app on port 443, and have the chat app link back to the PHP site. PHP uses apache. I can't find any easy way to do this. Been at this problem for days.
After much much research, trial and error I've figured out a few things.
My site consists of mainly PHP, I want to use node.js on a separate page as a chat app. I thought this would be easy, but I was mistaken. It's a lot of pain to get both node.js and PHP to work together flawlessly, and if I knew back then what I know now I might have went a different route. But I have things working for the most part and I am happy.
Some useful info:
If you want to link back to 80 or 443 from your node page, use the full URL with http/s.
If you want to use a virtual host it's only possible on Apache 2.4+ because socket.io can't communicate through it without some apaache mods that allow websocket proxing. It's also possible with NGINX from what I hear but I am less familiar with it.
So in the end I am just keeping the port number and allowing hyper links between the two. This is a temporary solution until I upgrade to either Apache 2.4 or NGINX.

Running multiple listening scripts on different ports in laravel

I have a project to make a chat app between mobile and java clients with my laravel website acting as a mediator for communication between them. I am new to laravel, so maybe some of the terms may not be correct.
So basically the problem is to run a websocket server on one port and simultaneously run a xmpp server to communicate with fcm/android on another port.
Individually they both are working fine on commands set by me.
But I am not able to run them simultaneously.
How should I go about it.
Secondly I don't know if it is fine to run two endless scripts on a simple website server.
I running websocket with Laravel too.
And I use Swoole to drive it.
https://github.com/swooletw/laravel-swoole

I am new to cakephp and I am wondering if PhpMyadmin and my cakephp app should be runnning on the same port?

I should be creating a database on phpmyadmin and connecting this database to my cakephp trial project. Should both be running on the same port? (ex:8888) or is it okay that each one of them is running on a different port? Thanks.
phpMyAdmin is a web-based interface to help administrators manage their MySQL databases. It usually runs on whatever port your webserver is using, typically 80 or 443 (for https traffic).
MySQL normally isn't exposed publicly, although your CakePHP application needs to be able to access MySQL directly (either through socket connections or by TCP/IP networking). The default MySQL port is 3306.
I think the CakePHP default is 8765, so your Cake project is probably running its own webserver on that port.
So, by default, none of your applications are conflicting. You don't want anything running on the same port because only one application can use a port at a time. Whichever application grabs the port gets to use it, and the other application probably will fail to start correctly and give an error message.
So it sounds like everything is working correctly.

PHP Websocket on Webserver

A few days ago I setup this WebSocket server from http://code.google.com/p/phpwebsocket/
It works excellent on my localhost by using Xampp. Then, I uploaded it to my webspace on Strato, but now I am not able to connect to the server.
I changed the the sockets connection to my domain but it didn`t work
Client.html:
var host = "ws://xxxxxxxx.com:12345/Websocket/server.php";
Server.php:
$master = WebSocket("xxxxxx",12345);
I already tried it with different port(80,443,12345,8080,8000....), using the IP address in server.php instead of the domain.
I also used absolute and relative paths in the client.html.
From the projects page http://code.google.com/p/phpwebsocket/ someone suggested to use 0 or 0.0.0.0 in the server.php, but that didn`t work either.
In the client.html it just shows:
WebSocket - status 0
Disconnected - status 3
My guess that the problem is that Strato is blocks me from using WebSockets.
Is it possible to run WebSockets on my webspace?
My bet is that your host is blocking incoming requests to the socket. Your not supposed to run scripts like phpwebsocket within a web service (it is a server itself). This confuses a lot of people since PHP is typically used for scripting webpages, not for coding daemons.
I say this because you mentioned running the script within Xampp, and referred to your hosting service as 'webspace'.
If this is the case you will have to upgrade to a virtual server package so that you can run your own services.
Okay, to bring this to an end.
I found a solution to use my websockets app and I´ve got an explanation why it did not work on my shared hosting solution.
I contacted Strato who told me that they don`t allow Websocket on shared hosting. The only way to get a similiar result would be to use AJAX Long Pooling.
Now I purchased to a Virtual Server and my websocket app works great now.
Thanks for your support.

Open a page available only on the server (backend proxy)

I have a frontend application that need to call a reporting services, opening a new window with a javascript function like this :
window.open('http://somedomain.com:8080/report')
What I wanna do now is, since the tomcat server is on the same machine of the backend application(and on the same machine of the web server - php), avoid to open the 8080 port on the internet.
In simple words, I need a way to connect the tomcat application server(through localhost) and proxy the connection to the frontend without requiring to open the port 8080 of the server to the all world. Is it possible ?
How can it be done ?
To generate html page on the server I use php...
EDIT/UPDATE
The page on the tomcat application server is not static, it has a loading mechanism and need user interaction ...
You could use PHP's cURL functions to get the information you need via PHP (using localhost:8080) and use this as a PHP proxy. Then use Ajax to retrieve the information from the PHP proxy.

Categories