Jump to content
php.lv forumi

load() failed


ray

Recommended Posts

man ir klase kurā ar load() tiek ielādēts *.xml fails no interneta lapas, bet ik pa brīdim šis fails nav pieejams (reizi pāris dienās uz īsu brīdi) un tad manā lapā rādās nesmuks error "...failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request...". Vai ir kāda iespēja, pirms tam pārbaudīt, vai šis fails man ielādēsies?

Paldies!

Link to comment
Share on other sites

try - catch?

 

Rekā es no twittera dabūju json datus, ik pa piecām minūtēm. Ja nav 5 min pagājušas, VAI serviss nav pieejams, tad ņemu lokālo failu.

 

	//Atjaunojam twittera JSON datus ik 5 minūtes
function updateTwitter(){
	$path = "myTwitterJson.json";
	$url = "http://twitter.com/statuses/user_timeline/twitter_username.json?callback=twitterCallback2&count=6";
	$stat = stat($path);
	$last_mod = (int)$stat[9]; //dabujam modificeto timestamp
	$delta_mins = time() - $last_mod;
	if($delta_mins > 300){ //defaultā 5 minūtes = 300 sekundes
		if($json_data = @file_get_contents($url)){ //Suppress warnings, ja neizdodas dabūt datus
			file_put_contents($path,$json_data);
		}else{
			touch($path);//Pabakstam, lai nav jāmēģina atkal, ja neizdevās ielikt contentu
		}
	}	
}

Edited by briedis
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...