boemboem Posted January 12, 2009 Share Posted January 12, 2009 I'm not a coder, but I try to find my way between other mans lines I had some great help beforre, but I need some more help with filling a array from a text file. I thought I could do it like this here beneath, but it seems it comes in a loop Can anyone tell me what goes wrong and how I can fix it? <?php //Fill this in with the list of servers $array = file('./text.txt'); $servers = implode('', $array); //$servers = array('./text.txt'); // 'www.google.nl', //'www.yahoo.com', //'www.klinkklareonzintoch.nl', // Function to check response time function pingDomain($domain){ $starttime = microtime(true); $file = @fsockopen ($domain, 80, $errno, $errstr, 10); $stoptime = microtime(true); $status = 0; if (!$file) $status = -1; // Site is down else { fclose($file); $status = ($stoptime - $starttime) * 1000; $status = floor($status); } return $status; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html> <body> <table> <?php foreach($array as $domainbase){ $status = pingDomain($domainbase); if ($status != -1) echo "<tr><td><img src=\"images/status/ok.gif\" /> <b>$domainbase </td><tr>"; else echo "<tr><td><img src=\"images/status/dead.gif\" /> <b>$domainbase</td><tr>"; } ?> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/140559-solved-fill-array-from-text-file/ Share on other sites More sharing options...
DeanWhitehouse Posted January 12, 2009 Share Posted January 12, 2009 Would it not be easier to do $array = file_get_contents("./text.txt"); $array = explode(",",$array); Not 100% on the above though Quote Link to comment https://forums.phpfreaks.com/topic/140559-solved-fill-array-from-text-file/#findComment-735533 Share on other sites More sharing options...
rhodesa Posted January 12, 2009 Share Posted January 12, 2009 hey again... how is the file organized? new server on each line or separated by commas? new server on each line: $servers = file('./text.txt'); commas: $servers = explode(',',file_get_contents('./text.txt')); Quote Link to comment https://forums.phpfreaks.com/topic/140559-solved-fill-array-from-text-file/#findComment-735537 Share on other sites More sharing options...
boemboem Posted January 12, 2009 Author Share Posted January 12, 2009 well, it's a server on each line, like: www.coldcharlie.nl www.google.nl www.yahoo.nl but there is a tiny problem: please take a look here: http://www.coldcharlie.nl/beta1/multi.php only the 3th domain is offline, it looks like after the first domain the rest is offline. <?php //Fill this in with the list of servers //$array = file('./text.txt'); //$servers = implode('', $array); $array = file_get_contents("./text.txt"); $servers = explode(',',$array); //$servers = array( //'www.google.nl', //'www.yahoo.com', //'www.klinkklareonzintoch.nl', //); // Function to check response time function pingDomain($domain){ $starttime = microtime(true); $file = @fsockopen ($domain, 80, $errno, $errstr, 10); $stoptime = microtime(true); $status = 0; if (!$file) $status = -1; // Site is down else { fclose($file); $status = ($stoptime - $starttime) * 1000; $status = floor($status); } return $status; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html> <body> <table> <?php foreach($servers as $domainbase){ $status = pingDomain($domainbase); if ($status != -1) echo "<tr><td><img src=\"images/status/alive.gif\" /> <b>$domainbase </td><tr>"; else echo "<tr><td><img src=\"images/status/dead.gif\" /> <b>$domainbase</td><tr>"; } ?> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/140559-solved-fill-array-from-text-file/#findComment-735624 Share on other sites More sharing options...
DeanWhitehouse Posted January 12, 2009 Share Posted January 12, 2009 Not sure if it will help but trying echoing the status and the domain name in the loop to check them. Do they look correct? Quote Link to comment https://forums.phpfreaks.com/topic/140559-solved-fill-array-from-text-file/#findComment-735631 Share on other sites More sharing options...
boemboem Posted January 12, 2009 Author Share Posted January 12, 2009 hey again... how is the file organized? new server on each line or separated by commas? new server on each line: $servers = file('./text.txt'); commas: $servers = explode(',',file_get_contents('./text.txt')); thanks again!, that was the sollution Quote Link to comment https://forums.phpfreaks.com/topic/140559-solved-fill-array-from-text-file/#findComment-735632 Share on other sites More sharing options...
boemboem Posted January 12, 2009 Author Share Posted January 12, 2009 hey again... how is the file organized? new server on each line or separated by commas? new server on each line: $servers = file('./text.txt'); commas: $servers = explode(',',file_get_contents('./text.txt')); thanks again!, that was the sollution IU thought it was the sollution, but it seems to accept every url, even false urls <?php //Fill this in with the list of servers $servers = file('./text.txt'); $array = explode(",",$array); // Function to check response time function pingDomain($domain){ $starttime = microtime(true); $file = @fsockopen ($domain, 80, $errno, $errstr, 10); $stoptime = microtime(true); $status = 0; if (!$file) $status = -1; // Site is down else { fclose($file); $status = ($stoptime - $starttime) * 1000; $status = floor($status); } return $status; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html> <body> <table> <?php foreach($servers as $domainbase){ $array = pingDomain($domainbase); if ($status != -1) echo "<tr><td><img src=\"images/status/alive.gif\" /> <b>$domainbase </td><tr>"; else echo "<tr><td><img src=\"images/status/dead.gif\" /> <b>$domainbase</td><tr>"; } ?> </table> </body> </html> The text.txt = organised as: www.url.com www.url2.com etc etc Quote Link to comment https://forums.phpfreaks.com/topic/140559-solved-fill-array-from-text-file/#findComment-735716 Share on other sites More sharing options...
rhodesa Posted January 13, 2009 Share Posted January 13, 2009 <?php //Fill this in with the list of servers $servers = file('./text.txt'); $array = explode(",",$array); // Function to check response time function pingDomain($domain){ $starttime = microtime(true); $file = @fsockopen ($domain, 80, $errno, $errstr, 10); $stoptime = microtime(true); $status = 0; if (!$file) $status = -1; // Site is down else { fclose($file); $status = ($stoptime - $starttime) * 1000; $status = floor($status); } return $status; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html> <body> <table> <?php foreach($servers as $domainbase){ $status = pingDomain($domainbase); if ($status != -1) echo "<tr><td><img src=\"images/status/alive.gif\" /> <b>$domainbase </td><tr>"; else echo "<tr><td><img src=\"images/status/dead.gif\" /> <b>$domainbase</td><tr>"; } ?> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/140559-solved-fill-array-from-text-file/#findComment-735890 Share on other sites More sharing options...
boemboem Posted January 13, 2009 Author Share Posted January 13, 2009 Now they are all offline, and that is not corrdct either http://keurmerk.coldcharlie.nl/multi.php Quote Link to comment https://forums.phpfreaks.com/topic/140559-solved-fill-array-from-text-file/#findComment-736011 Share on other sites More sharing options...
uniflare Posted January 13, 2009 Share Posted January 13, 2009 what does it say without the @ supression before fsockopen? rhodesa actually posted correct code. you were probably getting false positives before since you were saving the result in $array, rather than in $status. I believe there is a problem with your fsockopen call (never used it myself). When working with code its always best never to use suppression symbols ( @ ), until the script is finished, even then its bad practice to need them, or want them. Quote Link to comment https://forums.phpfreaks.com/topic/140559-solved-fill-array-from-text-file/#findComment-736016 Share on other sites More sharing options...
boemboem Posted January 13, 2009 Author Share Posted January 13, 2009 Can the problem be that I'm behind a proxy atm? I thought it was server sided so that didnt came to my conclusion in the first place. Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/g35003/coldcharlie.nl/subdomains/keurmerk/multi.php on line 11 Warning: fsockopen() [function.fsockopen]: unable to connect to www.coldcharlie.com :80 (Unknown error) in /var/www/g35003/coldcharlie.nl/subdomains/keurmerk/multi.php on line 11 Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/g35003/coldcharlie.nl/subdomains/keurmerk/multi.php on line 11 Warning: fsockopen() [function.fsockopen]: unable to connect to www.coldcharlie.nl :80 (Unknown error) in /var/www/g35003/coldcharlie.nl/subdomains/keurmerk/multi.php on line 11 Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/g35003/coldcharlie.nl/subdomains/keurmerk/multi.php on line 11 Warning: fsockopen() [function.fsockopen]: unable to connect to www.coldcharlie.com :80 (Unknown error) in /var/www/g35003/coldcharlie.nl/subdomains/keurmerk/multi.php on line 11 Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/g35003/coldcharlie.nl/subdomains/keurmerk/multi.php on line 11 Warning: fsockopen() [function.fsockopen]: unable to connect to www.coldcharlie.nl :80 (Unknown error) in /var/www/g35003/coldcharlie.nl/subdomains/keurmerk/multi.php on line 11 Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/g35003/coldcharlie.nl/subdomains/keurmerk/multi.php on line 11 Warning: fsockopen() [function.fsockopen]: unable to connect to www.coldcharlie.notgood :80 (Unknown error) in /var/www/g35003/coldcharlie.nl/subdomains/keurmerk/multi.php on line 11 Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/g35003/coldcharlie.nl/subdomains/keurmerk/multi.php on line 11 Warning: fsockopen() [function.fsockopen]: unable to connect to www.coldcharlie.omg :80 (Unknown error) in /var/www/g35003/coldcharlie.nl/subdomains/keurmerk/multi.php on line 11 Quote Link to comment https://forums.phpfreaks.com/topic/140559-solved-fill-array-from-text-file/#findComment-736026 Share on other sites More sharing options...
uniflare Posted January 13, 2009 Share Posted January 13, 2009 Are you hosting off your own computer? or off a public server? If its a remote server either paid or free you may have to ask the administrator to enable allow_url_fopen, and check the HOSTNAME is set correctly in the configuration. If it is a free or paid remote server i think the only ones who can help you now are the server admins. If you do have access to the servers core configuration files then we can help . Quote Link to comment https://forums.phpfreaks.com/topic/140559-solved-fill-array-from-text-file/#findComment-736041 Share on other sites More sharing options...
boemboem Posted January 13, 2009 Author Share Posted January 13, 2009 It was good before but ok, i looked at the phpinfo.php: Directive Local Value Master Value allow_url_fopen On On Quote Link to comment https://forums.phpfreaks.com/topic/140559-solved-fill-array-from-text-file/#findComment-736053 Share on other sites More sharing options...
rhodesa Posted January 13, 2009 Share Posted January 13, 2009 maybe you have extra whitespace that it doesn't like...i added trim here: <?php //Fill this in with the list of servers $servers = file('./text.txt'); //$array = explode(",",$array); //this line wasn't doing anything // Function to check response time function pingDomain($domain){ $starttime = microtime(true); $file = fsockopen ($domain, 80, $errno, $errstr, 10); $stoptime = microtime(true); $status = 0; if (!$file) $status = -1; // Site is down else { fclose($file); $status = ($stoptime - $starttime) * 1000; $status = floor($status); } return $status; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html> <body> <table> <?php foreach($servers as $domainbase){ $status = pingDomain(trim($domainbase)); if ($status != -1) echo "<tr><td><img src=\"images/status/alive.gif\" /> <b>$domainbase </td><tr>"; else echo "<tr><td><img src=\"images/status/dead.gif\" /> <b>$domainbase</td><tr>"; } ?> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/140559-solved-fill-array-from-text-file/#findComment-736133 Share on other sites More sharing options...
boemboem Posted January 13, 2009 Author Share Posted January 13, 2009 Trim did the trick, see the result here gents http://keurmerk.coldcharlie.nl/form.html << this is for putting in the url http://keurmerk.coldcharlie.nl/multi.php << here will the results be displayed add url to test it Quote Link to comment https://forums.phpfreaks.com/topic/140559-solved-fill-array-from-text-file/#findComment-736147 Share on other sites More sharing options...
DeanWhitehouse Posted January 13, 2009 Share Posted January 13, 2009 I added some to point out some bugs to you http://keurmerk.coldcharlie.nl/multi.php Quote Link to comment https://forums.phpfreaks.com/topic/140559-solved-fill-array-from-text-file/#findComment-736155 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.