Reviews, updates and in depth guides to your favourite mobile games - AppGamer.com
|
|
If remote file exists or timeout.... |
Page: 1 | Reply |
Mar 3rd 2002 | #34058 Report |
Member since: Mar 18th 2001 Posts: 1452 |
Is it possible to timeout an operation and move on, or detect if a file on another server is reachable, and if not after a period of time, then show an error message such as "news unavailable"? I syndicate GeekNews and /. headlines on my site, and sometimes GN goes down. If it does, the headline grabber script cant pull the backend.txt file from their server, and it won't let my page load. If I notice it, I have to go in there and remove the script until GN is back up. |
Reply with Quote Reply |
Mar 3rd 2002 | #34087 Report |
Member since: May 24th 2001 Posts: 358 |
http://www.php.net/manual/en/features.remote-files.php use a handy dandy if(!) command, like they do in their example. |
Reply with Quote Reply |
Mar 3rd 2002 | #34090 Report |
Member since: Mar 18th 2001 Posts: 1452 |
Aha! I know how to do it with local files, but I didn't know the same principles would hold true with remote files. Thanks.
|
Reply with Quote Reply |
Mar 3rd 2002 | #34110 Report |
Member since: Mar 18th 2001 Posts: 1452 |
:( I just get errors. Something about a bad file descriptor. I tried several different attempts. I hate trying to implement code into scripts someone else has written (old news grabbing script I found a long time ago).
|
Reply with Quote Reply |
Mar 3rd 2002 | #34111 Report |
Member since: May 24th 2001 Posts: 358 |
Whats the script look like?
|
Reply with Quote Reply |
Mar 3rd 2002 | #34121 Report |
Member since: Mar 18th 2001 Posts: 1452 |
I took out my failed attempts, so I could upload the original file. [code]<?php $backend = "http://www.geeknews.net/ultramode.txt"; $items = 0; $time = split(" ", microtime()); srand((double)microtime()*1000000); $cache_time_rnd = 300 - rand(0, 600); if ( (!(file_exists($cache_file))) || ((filectime($cache_file) + $cache_time - $time[1]) + $cache_time_rnd < 0) || (!(filesize($cache_file))) ) { $fpread = fopen($backend, 'r'); if(!$fpread) { // echo "$errstr ($errno)<br>\n"; // exit; } else { $fpwrite = fopen($cache_file, 'w'); if(!$fpwrite) { // echo "$errstr ($errno)<br>\n"; // exit; } else { while(! feof($fpread) ) { $buffer = ltrim(Chop(fgets($fpread, 256))); if ($buffer == "%%") { $title = ltrim(Chop(fgets($fpread, 256))); $link = ltrim(Chop(fgets($fpread, 256))); $date = ltrim(Chop(fgets($fpread, 256))); $time = ltrim(Chop(fgets($fpread, 256))); $submit_handle = ltrim(Chop(fgets($fpread, 256))); $submit_email = ltrim(Chop(fgets($fpread, 256))); $k = substr($title, 0, 60) . "..."; if (($title != "") && ($items < $max_items)) { fputs($fpwrite, "$link_prefix<A HREF=\"http://www.geeknews.net$link\" TARGET=\"$target\">$k</A>$link_postfix"); $items++; } } } } fclose($fpread); } fclose($fpwrite); } if (file_exists($cache_file)) { include($cache_file); } ?>[/code] |
Reply with Quote Reply |
Page: 1 | Back to top |
Please login or register above to post in this forum |
© Web Media Network Limited. All rights reserved. No part of this website may be reproduced without written permission. Photoshop is a registered trademark of Adobe Inc.. TeamPhotoshop.com is not associated in any way with Adobe, nor is an offical Photoshop website. |