Which Ratchet Component to Use - php

Brief Explanation...
I started working with Ratchet about 6 hours ago so my question my be a little basic... I have an existing website that has a big counter in the middle of one of the pages. The counter represents how many people have signed up to a particular form.
I would like this counter to update immediately whenever a person signs up to the website. In other words, there must be a web socket set up in order to be alerted when a new person has signed up to the site.
My Question
Before I go ahead and attempt to write the code, I would like to know which Ratchet component I should be using. I have gone through the introductions and tutorials and I think I should be using the WAMP Component but I am not 100% sure, and it is also the only tutorial I wasn't able to get working...
In short, which Ratchet Component should I use to update a counter on a website?

It really depends on what you are trying to accomplish
here's what you need to put in mind:
if you are trying to do a simple websocket application that targets simple 1 server to 1 client communication it is good to use the MessageComponentInterface.
but if you like to do a websocket application that would allow you to send from 1 server to multiple clients it is easier to accomplish this with a WAMP Component.
Your decision would depend on what your application requires.

Related

PHP with socket.io or recreate everything in node.js and socket.io?

I'm currently planning on coding a private project, to be more specific a virtual chat room, where avatars can walk around chat.
Now I'm literally a little confused, which language should be used to code it in. For now I've used PHP for the backend things, such as authentification and HTML for the frontend.
But i know i will need to use Javascript, to draw the chatroom assets to a canvas element. And i will need to use socket.io (node.js) for the chat and the packets.
Now my question, can I even use PHP in the backend and use socket.io for the communication between the server and the client and the chat itself?
For now the process is the following:
User logs into a account, the background check is done in php
User gets redirected to a Dashboard
User selects the menu point world
User selects a chat world and gets redirected to another site which contains a canvas and a chatbox
Screenshot of step 3: Select world
Screenshot of step 4: Canvas with chatbox
How could I create a socket after building the canvas to use socket io to communicate with the server and to create the chat application?
Would it be easier to code the whole site without PHP and just using node.js and socket.io (Also for the user autentification etc) ?
I appreciate any kind of suggestions and help
hmmm I assume you have good PHP skills but rather new to nodejs/socketio.
Yes nodejs can be better in real-time but it's rather for achieving scalability and it has its ecosystem, if you don't need either you can do it in PHP too.However, you can have both php and nodejs and that's perfeclty sane.
It will probably go like this : php for http requests and nodejs/socket.io for websockets connections, this setup will work if you don't need to call php from nodejs nor vice-versa(but both can still access the same database).
Now if you need to call either from either there are ways including message queues(like RabbitMQ) or exposing an HTTP API from one or either of them.
As for coding the whole thing in nodejs I wouldn't do that, php is pretty good at the tasks you mentioned, I still think that using nodejs for chats is going to be better .
Now you mentioned that it's private, in the future team members matter.
If this project is for learning purposes I do think that nodejs skills would be good to have under belt whether you need its scalability and/or ecosystem or not.

local website connect to wordpress online

Long time reader first time asker, if my question is silly or missing info or miss titled lemme know and I'll fix it.
Okay, so I'm working at a community center for the next 8 weeks as a tech help assistant, I'm also a CS student.
They have a web application that is quite old running locally on an iis server (version 7). It's for keeping track of their members, events and registration It's written in asp.net and is using and Access database. They also have a wordpress website (php, mysql, apache) for advertising events and sharing information about what's going on in the community.
What they would like is to link their wordpress to the local application. I've been racking my brain about if this is even possible or not. I'm leaning towards not possible because the local application and shouldn't be outward facing as it has sensitive data on it and was not designed to be secure in the face of would-be hackers.
The only solution that I could think of is create a "walled off" section of the computer hosting the local application. Also an outward facing port that accepts incoming data from the wordpress site that is then passed onto the access database as an update (increasing a counter for the amount of people registered to a program). It needs to be possible for a file to have some kind of global (from the web) executable permissions and have all the other files on the localhost computer locked down from this global permission.
We would also need to be able to get 2 boolean values from the local app for the wordpress site. This is for if the program/camp/whatever is full and if the update was unsuccessful in the event of something going wrong. I'm just not sure if something like that is even possible and where to start with that. The most important thing is that it's secure.
If a secure API could work I have time to create something like that.
I don't have enough time to upgrade their local system to make it safe enough to be online because I have to run tech help sessions. I know that is the most realistic option.
Thanks very much
What they would like is to link their wordpress to the local
application. I've been racking my brain about if this is even possible
or not. I'm leaning towards not possible because the local application
and shouldn't be outward facing as it has sensitive data on it and was
not designed to be secure in the face of would-be hackers.
I think you've hit the nail on the head right there. It looks like you have a decent understanding of the situation but not of their internal app. The fact is that it's hard to scope something like this without getting in and getting details. Step 1 would be to see if you can talk to whoever it is that built the thing and get their feedback. It might be secure enough to expose some sort of connection.
Really there's not enough information here to determine a good answer, and you should be wary of anyone that says it's secure. There are a ton of factors that go into web security.
You might be able to throw together a basic RESTful API with authentication to send only to the wordpress site's IP. But if it's sharing the IP that information can be consumed by third parties so you'll have to decide if that is an okay risk.
I wouldn't try and expose everything and partition with apache. A basic RESTful API with authentication would be best at first glance IMO. That way you only show consumable data and limit what can be used.

Create web app and mobile app with same MySQL DB on web server

Hi all,
i want create mobile app (i use phonegap) that retrieve and insert data in MySQL Database on web server also i will create website that connected to the same Database using (PHP).
I need guidance:
What topics should i know/use ?
What things should be implemented in Web development process ?
Can i use shared host or i will have to rent dedicated server ?
Is phonegap the right choice to accomplish the project ?
.........
Any guidance will be great.
Thank you All.
Your lack of familiarity with the technologies involved leads me to believe you are making a mole hill out of a mountain. All the skills involved need time/effort and no one answer here will cover your question.
There are various methods to achieve what you ask... I suggest starting with learning how to write some HTML5, then move on to doing a bit of Javascript and then follow it with a bit on jQuery. These skills are what you will use to place text on your web page or app.
After that, learn how to install MySQL, Apache, MySQL and PHP on your laptop. These skills will help you save data on to a server.
Then you need to learn how to combine them so that the data sent from your web app gets checked prior to saving on the server.
Then follow with how to read the data from the server and prepare it for re-display back on your web page or web app.
Once that is done - learn how to use the PhoneGap build service so you can package your app and try it on your device.
I suspect if you start now, and do 10-20 hours a week, you might get something buggy working by Christmas.
Best of luck!

Should I separate the web-service interface from the other parts of the system?

I'm developing a system (o rly?!), a regular system. This system maybe considered normal: CRUD's are all over the place. BUT, I also need to access his data as a web service. I'm developing both: the system and the web service, using Laravel 4.
I have controllers, of course, for all the CRUDs on the system so an user can be able to put information on the database. Pretty simply stuff...so far!
As I said: I need to consume data on a web-service format. I need to make request and record data to the server throught a JSON string and REST verbs. That being said, here comes the question:
Should I create a whole new project to access the data as a web service and separate it from the original project (cruds) or this is just a stupid idea of mine?
I think this might help on the security and on the cohesion on both projects.
Any answer is welcome ans thanks in advance! =D
If you are a coder who can easily organise an additional layer into your current app, to create the web-service layer, then do it.
If (like me, and probably most others) you'll just get swamped in a mess of files and folders, and end up changing code which impacts your already existing app - stay well clear! Write a new web-service app!
Separate the concerns, and sleep happy at night that both animals are caged up separately so they can't kill each other.
Although...you are using laravel. So you can actually create separation quite nicely in one app by using packages (were called bundles in L3). You still might run into the risk that you mess up some code of your current app, but if you are strict with yourself, you should be ok.
One question I'd ask yourself is why not just have the app ONLY be a web service, and create clients that meet any needs you want? It does seem odd to have an app being used as a web server and also as a web service. You may run into all sorts of performance problems if you try to do both in the same app.
UPDATE:
For a definitive answer on if you are doing this the right way: I say no, you aren't doing it the right way. Create a web service from your app, and ONLY allow it to be a web service. Then create client apps (web service consumers) to meet any needs you have for displaying the data.

server sent events - One client to update them all

Alright, so here is what I am trying to achieve. I have a custom built Point of Sale done in VB.net. What I want to add now is a customer facing android tablet that shows the reciept as it's entered into the Point of Sale.
Brainstorming how to do this I came up with the idea to use a php hosted script (no problem as the POS has a mysql-php web backend on a local server) that would use server sent events to update the tablet. The issue I'm facing is I'm not sure how to update the server (and thus the tablet) from another client (this one being the Point of Sale).
I can't seem to find any examples other than clocks for server sent events, does anyone have a link to something similar or perhaps a better solution than what I came up with?
I had considered using an app like idisplay and just extending that way, but it doesn't support windows 8 which is what the POS is running. I also considered websockets, but I don't have a firm enough grasp of that to get it up and running. I could make an app for the tablet, but I don't really want to do that, most of my background with app development is on iOS and I don't personally like java as a development language.
EDIT 1: Alright, so I'm understanding better how I would need to make this work.
So far I have it working where I can input a $_GET variable to change the value and the next time an update is pushed it works properly. I just need to verify there's new or different data before it pushes the data.
Is there a better example than this http://www.html5rocks.com/en/tutorials/eventsource/basics/ concerning how to push updates on demand to the listening clients?

Categories