Connection timeout problems with fopen()

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
GoroUnreal
-


Joined: 25 Nov 2006
Posts: 4

PostPosted: Sat Nov 25, 2006 11:54 pm    Post subject: Connection timeout problems with fopen() Reply with quote

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 View user's profile Send private message
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Sun Nov 26, 2006 12:15 am    Post subject: Reply with quote

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 View user's profile Send private message Visit poster's website
GoroUnreal
-


Joined: 25 Nov 2006
Posts: 4

PostPosted: Sun Nov 26, 2006 12:19 am    Post subject: Reply with quote

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 View user's profile Send private message
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Sun Nov 26, 2006 12:24 am    Post subject: Reply with quote

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 View user's profile Send private message Visit poster's website
GoroUnreal
-


Joined: 25 Nov 2006
Posts: 4

PostPosted: Sun Nov 26, 2006 12:37 am    Post subject: Reply with quote

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 View user's profile Send private message
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Sun Nov 26, 2006 12:45 am    Post subject: Reply with quote

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 View user's profile Send private message Visit poster's website
GoroUnreal
-


Joined: 25 Nov 2006
Posts: 4

PostPosted: Sun Nov 26, 2006 9:11 am    Post subject: Reply with quote

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 View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group