There is a home server with DDNS, it works from the outside, everything is OK. There is a website on PHP hosting, and it needs to check if the server is working.

I read, searched and came across 2 solutions for checking server operation - these are sockets or download any file from the server. It is simple and clear.

As a result, none of them works with DDnS. I can't figure out why. If I specify the direct ip instead of the URL (without the ddns domain), then it doesn't work either

Using file_get_contents (" http: // ". $ Ip. ":". $ Port. " /WorkPage.aspx "); - gives failed to open stream: Connection timed out , and specify the ip and port directly without the ddns domain. Using fsockopen or cURL is the same.

Immediately I enter the same address in the browser - everything works. (typos checked). I open a site from another network - everything works.

Hosting error? How to deal with it and in what direction to dig?

  • so maybe on that server with an Internet messed up? you try to make a request from wget console on it - if it passes, then you have to dig further php, and if you don’t go to the site or google, then you will need to dig in the server settings. - BOPOH
  • @BOPOH, server is working, there’s definitely no problem with it. Access to each other through the console is. But through PHP there is no - vsb95

3 answers 3

Try using curl , for example:

 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://".$ip.":".$port."/WorkPage.aspx'); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); $data = curl_exec($ch); curl_close($ch); 
  • Already tried through curl - does not work. Even your code didn't work - vsb95

Well, you need to understand what it means to "work" whether or not and with the help of what to check. For example, you can simply telnet periodically open 80/443 / which_to_Your_porty and determine the work by the answer. You can write a simple bash / sh script, for example, using wget:

 #!/bin/sh wget --output-document=/tmp/2.html -q --no-check-certificate --tries=3 --connect-timeout=4 --spider http://$1:$2 ret=$? if [ "$ret" == 0 ] then exit 0; else exit 1; fi 

To transfer to a script dns / ddns / ip port for example script.sh moy_site.com 80 Well, or a direct link can be, at your discretion.

  • unfortunately on the hosting you cannot use the console to run scripts, so this option is no longer possible - vsb95

Solved the problem is not the most aesthetic way:

on the hosting I made 2 php files - one stores the current ip, and then this file will be overwritten when the server is loaded, which, when changing its ip, will replace the ip in this file.

The 2nd file does a check: on 2ip.ru I still had the correct check on the server on / off, there is no api, therefore I just downloaded the ip check page and then parsed the result.

If someone has a suggestion how to do better, I will be grateful