building a fast redirect server - php

I want to create a tracking platform but am in need of some advice. What it has to do is the following:
Someone visits a link e.g. http://click.track.com/redirect?campaign=1&partnet_id=2
When visiting this link a user get's redirect to e.g. http://google.com/?xx=xx
I'm going to use redis since it's really fast and considering the following two options since I have the knowledge to build it in that way.
PHP
NodeJS
I'm thinking that NodeJS is going to be faster but would like to know opinions of other people. Maybe I just have to learn something else to make it work even better :)

I would look into HAPI server - this is a BATTLE tested node server that gives you SO many options. Express may work too but i put my trust in the HAPI server stack. Plus they have alot of great add ons and plugins.
https://hapijs.com/
Redis is also a great key value store as well - Look into CASSANDRA too
http://cassandra.apache.org/
https://redis.io/

You need to have a good hosting service provider like digitalocean, amazon cloud etc. for faster redirection. PHP or NodeJS it doesn't matter much when you have a faster hosting.

Related

How to check realtime server statistics and health - Laravel / PHP

Basically i would like to have some kind of server statistics on my dashboard. Is there any package out there that does this out of the box.
I know finding the health of the server is pretty simple, by checking the status code for 200. But what about other stats? Stats like, no of db queries, load on the server & db, no of visitors on the site right now etc. I know most of them are pretty simple, but is there any way of getting this information in realtime without slowing down the server.
Can we benifit from services like NewRelic Lite. We could use the api to get the information from NewRelic and just display them on the dashboard. Will that be a good idea?
EDIT:
I am also looking into nagios, which looks like an opensource alternative to NewRelic.
Any suggestions?
I guess it Laravel Server monitor could help you. I've never used but it could give you some "light".
New relic seems to be a very complex and complete service, you could benefit from it a lot. Display every type of information that they can give you, its basically one of the most complete services i've seem.
I think antonioribeiro/tracker is the best, Here is the link to the repo.
I have used it in many projects, Its well maintained and well updated. Good Luck.

Way to send information between two web browser clients?

I've done a LOT of research on my following problem, but it all ends up pointing to Websockets which I can't use because my host doesn't allow command line or ssh. I've also tried the postMessage(data, targetDomain) technique, but that's not entirely where I want to go either.
Here's what I want to do:
Execute javascript from one person to the other users that are on that page without reloading it or anything.
Example: A user clicks a button on the page and it sends a javascript code that automatically executes a function on every other listeners page. Kind of like a chat feature you could say, but less dense maybe?
This is my first time exploring this field so I'm a bit confused over the concepts. I've read multiple documentations of programs that offer socket like usage, but not really any luck here. (Like I said, I can't really use sockets because of my host).
Any help is appreciated, thanks!
If you are on a hosting platform that doesn't allow WebSockets then you can outsource the realtime communications layer to a hosted realtime service (I work for Pusher which is one such service).
Hosted services tend to have a free tier so depending on what you are trying to achieve that may be enough. If not, then contact them, explain your app and your situation and they may be able to help.
If you want to use a self hosted solution then you may need to go with something HTTP-based. But, again, if you are on a small shared hosting platform this may be quite resource intensive and your hosting provide may tell you off.
If updates aren't all that frequent they you could use standard AJAX polling at reasonably long intervals. It sounds like you'd like to avoid this though.
Personally, I'd recommend using a hosted service as what you are trying to achieve is inherently difficult with PHP as it was built with request/response in mind.
Related: Realtime websocket-like behavior possible on Heroku?

Partner-website-hosted Web App without exposing source code - Possible?

Apologize if this particular problem has been answered already (a search didn't turn anything directly relevant up).
We are developers of a web app that is used to provide community commenting and "social" to our partners websites. Our app uses Javascript and HTML on the front end, PHP and mySQL on the back.
Currently we are running everything through our own servers, which is getting very expensive.
We would like to ask our partners if we can host the app through their servers, with them getting a discount to our monthly charge due to the bandwidth/cpu load they would help us share.
My question is, is there a way to host our app through our partner's web servers in such a way that we can offload most of the CPU time and bandwidth without exposing our source code?
I would greatly appreciate any ideas/help!!
Thank you very much all!
If you also serve static or rarely changing content your clients could run a caching reverse proxy to remove some load from your servers without giving them any source code at all. But you need to implement caching headers for this to work properly.
You may want to look into nginx.
On second thought: Did you try to compile your scripts using facebooks Hip-Hop for PHP? First of all the script should perform way better, second of all, if you still had to outsource the hosting, you deploy a compiled program, no source code involved.
If you put the code on their server they can find out. So that won't be 100% working. Though you can make it difficult but it's still not great.
Most doable solution might be to separate parts of the application and share them. So: You give away a process (so source and other needed data) but it's only part of the total. That way no partner has your total solution but you do outsource the parts.

Flash browser game - HTTP + PHP vs Socket + Something else

I am developing a non-real time browser RPG game (think Kingdom of Loathing) which would be played from within a Flash app. At first I just wanted to make the communication with server using simply URLLoader to tell PHP what I am doing, and using $_SESSION to store data needed in-between request.
I wonder if it wouldn't be better to base it on a socket connection, an app residing on a server written in Java or Python. The problem is I have never ever written such an app so I have no idea how much I'd have to "shift" my thoughts from simple responding do request (like PHP) to continuously working application. I won't hide I am also concerned about the memory and CPU usage of such Server app, when for example there would be hundreds of users connected. I've done some research.
I have tried to do some research, but thanks to my nil knowledge on the sockets subject I haven't found anything helpful. So, considering the fact I don't need real time data exchange, will it be wise to develop the server side part as socket server, not in plain ol' PHP?
Since your game isn't something that's working in realtime you probably don't need to go down the socket route, though it's certainly a viable option. The nice thing about sockets is that updates would be instant without requiring page refresh (or server poll), so you're right to at least consider it.
If you do want to do a more real-time server setup, you might consider using something like Electroserver - this abstracts out much of the setup for you so you don't have to write your own server from scratch, plus it's free up to a certain number of concurrent users if I recall correctly.
Finally, a third option you have is a modified POST approach using AMF. Look into AMFPHP, it lets you call methods on a PHP back-end directly from your flash application. A little bit faster and easier than simply using POST stuff, but not quite as seamless as a socket connection or a specifically built gaming server.
Lots of options out there, it sounds like you are aware of this and kudos for trying to come up with the best approach rather than just rolling with what you know! I hope this helps, let me know if you have any questions.
Here's a link to Electroserver - http://www.electro-server.com/

Best way to let a remote bot (agent) and a web panel communicate (PHP)

Im in the process of writing a web panel that will manage game servers on local and remote servers. The remote servers will have a simple PHP bot on them that carries out the instructions given to it by the web panel.
My question is, what is the best way (taking into consideration performance and reponsiveness) to get the instructions from the web panel to the agents?
EG:
Sockets extension?
A memory table in the database called queue that the agent periodicly queries?
Please discuss all options, even if they may not seem better than alternatives :3
Use memcached and a giant array! :)
EDIT
Both sides of the equation can access the remote Memcached server the same way. Treating the big array as a stack of instructions. So the console can add new ones, and the bot can read, remove one, and perform it.
The cons. This is a really silly idea. Oh, and would be really easy to royally screw up if you aren't careful.
The pros. It is SUPER easy. And prolly really fast.

Categories