View previous topic :: View next topic |
Author |
Message |
GoroUnreal -
Joined: 25 Nov 2006 Posts: 4
|
Posted: Sat Nov 25, 2006 11:54 pm Post subject: Connection timeout problems with fopen() |
|
|
I'm using the following code in a php file on another server (outside my network), i'm using it to see if the index.php file exists (which would mean the server is online) and if it is print "server online". However even though the server is online it always gives me a connection timeout.
Code: |
if (!fopen("http://myipaddress:portnumber/index.php", "r"))
{
print "Server offline";
} else {
print "Server online";
fclose();
}
|
Thing is my server works and even using a proxy to see if my site on the server works does work.
So just wondering if there's a setting i'm missing when it comes down to outside access to files via functions like fopen()?
Note: i'm using Abyss Web Server X1 (v 2.3.2) and the latest pre packaged php (v5.20)
Thanks |
|
Back to top |
|
 |
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Sun Nov 26, 2006 12:15 am Post subject: |
|
|
Try using readfile(), you might have better results.
Is that the exact code you are using? If so it looks like you have a syntax error.
Code: | if (!fopen("http://myipaddress:portnumber/index.php", "r")) |
should be
Code: | if (!(fopen("http://myipaddress:portnumber/index.php", "r"))) |
_________________ Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk |
|
Back to top |
|
 |
GoroUnreal -
Joined: 25 Nov 2006 Posts: 4
|
Posted: Sun Nov 26, 2006 12:19 am Post subject: |
|
|
AbyssUnderground wrote: | Try using readfile(), you might have better results.
Is that the exact code you are using? If so it looks like you have a syntax error.
Code: | if (!fopen("http://myipaddress:portnumber/index.php", "r")) |
should be
Code: | if (!(fopen("http://myipaddress:portnumber/index.php", "r"))) |
|
Thanks for the response. I don't get a syntax error with that code, don't think I ever have gotten an error from writing it that way.
Regardless, it timeouts with the readfile function =/ |
|
Back to top |
|
 |
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Sun Nov 26, 2006 12:24 am Post subject: |
|
|
Maybe you can make use of this code. It does pretty much what you want except instead of displaying text it adds a number to a file accordingly for my uptime stats.
Code: | <?php
$url="http://www.google.co.uk";
$check = file_get_contents($url);
if($check){
$fp = fopen("uptime_online.txt", "r");
$counton = fread($fp, 1024);
fclose($fp);
$counton = $counton + 1;
$fp = fopen("uptime_online.txt", "w");
fwrite($fp, $counton);
fclose($fp);
}
else{
$url="http://www.google.com";
$check = file_get_contents($url);
if($check){
$fp = fopen("uptime_online.txt", "r");
$counton = fread($fp, 1024);
fclose($fp);
$counton = $counton + 1;
$fp = fopen("uptime_online.txt", "w");
fwrite($fp, $counton);
fclose($fp);
}
$fp2 = fopen("uptime_offline.txt", "r");
$countoff = fread($fp2, 1024);
fclose($fp2);
$countoff = $countoff + 1;
$fp2 = fopen("uptime_offline.txt", "w");
fwrite($fp2, $countoff);
fclose($fp2);
}
?>
|
This is unmodified so you will have to disect it. _________________ Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk |
|
Back to top |
|
 |
GoroUnreal -
Joined: 25 Nov 2006 Posts: 4
|
Posted: Sun Nov 26, 2006 12:37 am Post subject: |
|
|
Nope =/ I changed your code to:
Code: |
<?
$url="http://myip:port/index.php";
$check = file_get_contents($url);
if($check)
{
print "Server online";
} else {
print "Server offline";
}
?>
|
And still timeouts
Seems like no php function concerning opening a file will work for me, so that's why i'm guessing maybe there's a setting that i'm missing which could be blocking it? Or do you think it might have to do with my router's firewall? |
|
Back to top |
|
 |
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Sun Nov 26, 2006 12:45 am Post subject: |
|
|
It could be the firewall disallowing PHP access to the internet. Temporaly disable it and try again. If not, then try another version of PHP, try version 4. _________________ Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk |
|
Back to top |
|
 |
GoroUnreal -
Joined: 25 Nov 2006 Posts: 4
|
Posted: Sun Nov 26, 2006 9:11 am Post subject: |
|
|
AbyssUnderground wrote: | It could be the firewall disallowing PHP access to the internet. Temporaly disable it and try again. If not, then try another version of PHP, try version 4. |
Disabling firewall didn't help =/ and I couldn't really be bothered to change the php that's installed heh. But no worries, it was only some little thing I wanted to do, nothing important. The site still works so that's all that matters.
Thanks for the help regardless =) |
|
Back to top |
|
 |
|