I have several VPS' and want to use PHP or shell scripting to display the ping in ms from the client to the server(s) so the user may compare which server to connect to. What is the best way to do this?
Assuming you want this to be asynchronous (so it doesn't stop the whole page from loading) then you could wrap something up in an Ajax call and then have a server-side script perform a ping on the $_SERVER['REMOTE_ADDR'] (IP of the person visiting the site). As for performing the ping itself, you should just be able to wrap that up in a "system('ping ..." call.
Hope that helps!
Depending on how sophisticated you want to get with your networking, you might want to give anycast a shot. The premise is that you give the same IP address to the two different VPS servers in the two different locations. When the client tries to connect to your server using a DNS lookup, it will find the single IP address, and depending on the closer server (ergo, better pinging server) should pickup that client. Cloudflare does this, and they explain it in their blog. Although, this might be seen a using a cannon to kill a mosquito, but it seems to work and it might even work for you. Here's some data that shows that Anycast is not evil.
Related
We have develop a CURL function on our application. This curl function is mainly to map the data over from 1 site to our form-field in our application.
However, this function has been working fine all the while and ready for use for more than 2 months. Yesterday, this fucntion was broken down. the data from this website is no longer able to map over. We are trying to find out why the problem is. When we troubleshooting, it shows that there is response timeout issue.
To re-ensure there were nothing wrong on our coding and our server performance is working, we have duplicates this instance to another server and try out the function. It was working perfectly.
Wondering if any one out there facing such problem?
What could the possibility to cause this issue?
When we are using cURL, will the site owner know that we are calling their data to map into ours server application? If so, is there a way that we can overcome this?
Could be the owner that block our server ip address? tht's why it function works well on my another server but not in the original server?
Appreciate your help on this.
Thank you,
Your problem description is far too generic to determine a specific cause. Most likely however there is a specific block in place.
For example a firewall rule on the other end, or on your end, would cause all traffic to be dropped, thus causing the timeout. There could also be a regular network outage between both servers, but that's unlikely.
Yes, they will see it in their Apache (or IIS) logs regularly. No, you cannot hide from the server logs - it logs all successful requests. You either get the data, or you stay stealthy. Not both.
Yes, the webserver logs will contain the IP doing all the requests. Adding a DROP rule to the firewall is then a trivial task.
I have applied such a firewall rule to bandwidth and/or data leechers a lot of times in the past few years, although usually I prefer the more resilient deny from 1.2.3.4 approach in Apache vhost/htaccess. Usually, if you use someone else's facilities, it's nice to ask for proper permission - lessens the chance you get blocked this way.
I faced a similar problem some time ago
My server IP was blocked from the website owner
It can be seen in the server logs. Google Analytics, however, won't see this, as cURL doesn't execute javascript.
Try to ping the destination server from the one executing the cURL.
Some advices are:
Use a browser header to mask your request.
If you insist on using this server, you can run trough a proxy.
Put some sleep() between the requests.
I'm making a network monitoring program with PHP.
I want to be able to connect to the DNS or DHCP Server and get all of the computers that belong to the network.
Currently I'm running nested for loops to ping every possible IP Address however it takes way to long with over 10 subnets.
I'm trying to change from doing it like a noob to doing it like a boss.
I want to get a list of all computer names and IP Addresses as well as if their IP was assigned Dynamically or Statically.
How should I do this?
There is no way to enumerate all hosts on a network, even pinging all of them isn't sufficient as some may not reply to ping. For the dynamically allocated ones you could query the DHCP server, but DHCP as a protocol does not support this, you'd have to write a daemon process and query the logs or assignment file.
If you do want to do it by pinging I'd suggest writing a small program the runs in the background and pings everything, keeping the results in memory, and then have your php script query that. This way you response time will be near immediate. So long as hosts don't appear and disappear too frequently (sounds unlikely) then this should be fine.
I have a dedicated webserver running PHP software which needs to automatically collect and update the IP's of a couple Windows and possibly Linux machines of mine which have dynamic IP's (roughly same idea as the no-ip.com client). The simplest thing to do I think is to run a service on each machine which simply pulls a unique URL from the webserver which can then lookup the client IP and match it with the URL etc.
$_SERVER["HTTP_CLIENT_IP"]
What's the best language/library/environment to build a client service which can make a URL request with easy access to the machine's external IP (to check for changes to the dynamic IP so as to not flood the webserver)? It need not be anything fancy, it doesn't even need to read anything from the server, it just has to make the URL request.
Besides web programming, I have some experience with Python and C and a few others. Any pointers or resources I can read up on the subject would be appreciated. Also, am I over-thinking this? Thanks
you can write a shell script with wget calls followed by a sleep in a loop.
wget performs http requests and it's available for windows and is already installed on all/some unix machines.
Mechanize is way overkill for making URL requests in Python. It's really really easy:
from urllib2 import urlopen
urlopen("my://url").read()
The first line may vary depending on your version of Python (for instance, it's urllib.request in Python 3.)
There are hundreds of "What's my IP" services out there; or you could even write your own! Plug one of those into the URL read to get the IP. You'll have to poll to work out when it changes, since you can't run code on the router.
If you already have some kind of method to do an URL request, do one each 10 minutes to this Page:
http://checkip.dyndns.org/Current%20IP%20Check.htm
wich will tell you "Current IP Address: XXX.XXX.XXX.XXX", and you only have to extract some string data.
(You only flood the whatsmyip webserver, and not your own anymore!)
Glad to Help
EGOrecords
I have a robot that I'm controlling via a browser. A page with buttons to go forward, reverse, etc is written in PHP hosted on an onboard computer. The PHP is just sending ASCII characters over a serial connection to a microcontroller. Anyway, I need to implement a failsafe so that when the person driving it gets disconnected, the robot will stop. The only thing I can think to do is to ping the person on the web page or something, but I'm sure there is a better way than that. The robot is connected either via an ad hoc network or a regular wireless network that is connected to the internet. Obviously if I go with the ping method then there will have to be a delay between the actual time disconnected and when it realizes it's been disconnected. I'd like this delay to be a small as possible, whatever the method used. I'd appreciate any ideas on how to do this.
Pinging a web client is somewhat unreliable, for you have to take into account, that the client ip might change.
On the other hand, you could emulate a "dead-man-button" via Ajax. Let the webpage send a defined command every now and then (maybe every 5 to 10 seconds). If the robot doesn't receive the message for some time, it can stop. The Ajax script could run in the background so the controlling user won't even notice anything.
This would of course mean, that your robot needs to have a counter which is incremented every second and reset when the message is received. The moment the timer variable is too high, FULL STOP
May I suggest you use a simple flash object embedded in the web browser to open a socket connection to a server on the robot? The server can be written in any suitable language - even PHP (cough).
Then it is a simple matter to detect immediately when the connection goes down, and implement your fail-safe approach.
HTTP is not a ideal protocol for robot control.
Good luck!
All I can think of is to include ajax code in your HTML that "pings" your server every X second. I believe that's what Facebook Chat does to know whether or not you are still online.
HTML 5 Web sockets might be the solution you are looking for but you have to consider that it won't be implemented by most of your users' browsers.
You might find this article interesting: http://www.infoq.com/news/2008/12/websockets-vs-comet-ajax.
Is it possible to implement a p2p using just PHP? Without Flash or Java and obviously without installing some sort of agent/client on one's computer.
so even though it might not be "true" p2p, but it'd use server to establish connection of some sort, but rest of communication must be done using p2p
i apologize for little miscommunication, by "php" i meant not a php binary, but a php script that hosted on web server remote from both peers, so each peer have nothing but a browser.
without installing some sort of
agent/client on one's computer
Each computer would have to have the PHP binaries installed.
EDIT
I see in a different post you mentioned browser based. Security restrictions in javascript would prohibit this type of interaction
No.
You could write a P2P client / server in PHP — but it would have to be installed on the participating computers.
You can't have PHP running on a webserver cause two other computers to communicate with each other without having P2P software installed.
You can't even use JavaScript to help — the same origin policy would prevent it.
JavaScript running a browser could use a PHP based server as a middleman so that two clients could communicate — but you aren't going to achieve P2P.
Since 2009 (when this answer was originally written), the WebRTC protocol was written and achieved widespread support among browsers.
This allows you to perform peer-to-peer between web browsers but you need to write the code in JavaScript (WebAssembly might also be an option and one that would let you write PHP.)
You also need a bunch of non-peer server code to support WebRTC (e.g. for allow peer discovery and proxy data around firewalls) which you could write in PHP.
It is non-theoretical because server side application(PHP) does not have peer's system access which is required to define ports, IP addresses, etc in order to establish a socket connection.
ADDITION:
But if you were to go with PHP in each peer's web servers, that may give you what you're looking for.
Doesn't peer-to-peer communication imply that communication is going directly from one client to another, without any servers in the middle? Since PHP is a server-based software, I don't think any program you write on it can be considered true p2p.
However, if you want to enable client to client communications with a php server as the middle man, that's definitely possible.
Depends on if you want the browser to be sending data to this PHP application.
I've made IRC bots entirely in PHP though, which showed their status and output in my web browser in a fashion much like mIRC. I just set the timeout limit to infinite and connected to the IRC server using sockets. You could connect to anything though. You can even make it listen for incoming connections and handle them.
What you can't do is to get a browser to keep a two-way connection without breaking off requests (not yet anyways...)
Yes, but its not what's generally called p2p, since there is a server in between. I have a feeling though that what you want to do is to have your peers communicate with each other, rather than have a direct connection between them with no 'middleman' server (which is what is normally meant by p2p)
Depending on the scalability requirements, implementing this kind of communication can be trivial (simple polling script on clients), or demanding (asynchronous comet server).
In case someone comes here seeing if you can write P2P software in PHP, the answer is yes, in this case, Quentin's answer to the original question is correct, PHP would have to be installed on the computer.
You can do whatever you want to do in PHP, including writing true p2p software. To create a true P2P program in PHP, you would use PHP as an interpreted language WITHOUT a web server, and you would use sockets - just like you would in c/c++. The original accepted answer is right and wrong, unless however the original poster was asking if PHP running on a webserver could be a p2p client - which would of course be no.
Basically to do this, you'd basically write a php script that:
Opens a server socket connection (stream_socket_server/socket_create)
Find a list of peer IP's
Open a client connection to each peer
...
Prove everyone wrong.
No, not really. PHP scripts are meant to run only for very small amount of time. Usually the default maximum runtime is two minutes which will be normally not enough for p2p communication. After this the script will be canceled though the server administrator can deactivate that. But even then the whole downloading time the http connection between the server and the client must be hold. The client's browser will show in this time its page loading indicator. If the connection breakes most web servers will kill the php script so the p2p download is canceled.
So it may be possible to implement the p2p protocol, but in a client/server scenario you run into problems with the execution model of php scripts.
both parties would need to be running a server such as apache although for demonstration purposes you could get away with just using the inbuilt php test server. Next you are going to have to research firewall hole punching in php I saw a script i think on github but was long time ago . Yes it can be done , if your client is not a savvy programmer type you would probably need to ensure that they have php installed and running. The path variable may not work unless you add it to the system registry in windows so make sure you provide a bat file that both would ensure the path is in the system registry so windows can find it .Sorry I am not a linux user.
Next you have to develop the code. There are instrucions for how hole punching works and it does require a server on the public domain which is required to allow 2 computers to find each others ip address. Maybe you could rig up something on a free website such as www.000.webhost.com alternatively you could use some kind of a built in mechanism such as using the persons email address. To report the current ip.
The biggest problem is routers and firewalls but packets even if they are directed at a public ip still need to know the destination on a lan so the information on how to write the packet should be straight forwards. With any luck you might find a script that has done most of the work for you.