If you visit designussion.com you will see a twitter feed just above the navigation im getting this error and have no idea how to fix it..... Warning: file_get_contents(http://search.twitter.com/search.atom?q=from:designussion&rpp=1) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 503 Service Unavailable in /home/onempsic/public_html/designussion/wp-content/themes/designussion/header.php on line 77 " PHP: anyone able to explain and help me out? Thank you
Are you able to use file_get_contents on other sites? Sounds like file_get_contents is disabled. Many hosts block this and fopen of other sites.
What jestep said is exactly right. You are being blocked from opening sites. So you can do one of two things... 1.) Create a php.ini file that allows it and put it in the same directory as the file calling or 2.) Write a function that will parse the results from the page copy it into your own server - then do what you need with it.
Are you getting this all the time? It seems like it's an issue on twitter.com's site, nothing to do with your site. They have a problem serving the request, and ofcourse you can't process that. Edit: actually, it's probably what the others are saying.. not sure. YOu may want to try and set allow_url_fopen to 1 in your php.ini. I got confused here because of the 503 error which I thought came from twitter
ok thank you. i have no knowledge of php so is there anywhere i could find a ready made php.ini file? Thanks
It just happened now, but its gone back to normal again without showing my latest tweet. Im very confused atm, when i first used the theme it worked fine....
Eh, look at the code it gives you "SERVICE UNAVAILBLE" That's not your script - that's them! Unless you want to code to accommodate for that error - nothing you can do really.
You can also do this in your .htaccess: Simply place php_flag allow_url_fopen On Code (markup): Also, to test if file_get_contents works, make a new file with this: <?php echo file_get_contents('http://www.google.com/'); ?> PHP: It should (obviously) show you the google homepage. Anyway, it does look like it's just twitter. Twitter (especially their search results api) goes down quite alot. You should build your site so that it does not fail when that happens. You need to cache the last working result and display that.
rite ok, i have it back to how it was but its not retrieving my latest tweet. here is the code im using.... <?php $twituser = get_option('theme_twitter_name');?> <?php if(!empty($twituser)): else : $twituser = "designussion"; endif; ?> <div class="twitter"> <div class="last-tweet"> <span class="twitname"><?php echo $twituser; ?></span>" <?php $prefix = ""; $suffix = ""; $feed = "http://search.twitter.com/search.atom?q=from:".$twituser."&rpp=1"; function parse_feed($feed) { $stepOne = explode("<content type=\"html\">", $feed); $stepTwo = explode("</content>", $stepOne[1]); $tweet = $stepTwo[0]; $tweet = str_replace("<", "<", $tweet); $tweet = str_replace(">", ">", $tweet); return $tweet; } $twitterFeed = file_get_contents($feed); echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix); ?> " PHP:
Right, well, you definitely don't want to be doing that. I think twitter may limit your ip address after you do more than 100 API calls an hour. That is probably the reason why you are receiving the 503 HTTP error.
You can try this, note I have not tested this so it may not work: (It's best if you try this locally first) (Note, if you're still banned for the rest of the hour it will obviously not work.) <?php $twituser = get_option('theme_twitter_name'); if (empty($twituser)) { $twituser = 'designussion'; } ?> <div class="twitter"> <div class="last-tweet"> <span class="twitname"><?php echo $twituser; ?></span> <?php $prefix = ""; $suffix = ""; $feed = "http://search.twitter.com/search.atom?q=from:". urlencode($twituser)."&rpp=1"; function parse_feed($feed) { $stepOne = explode("<content type=\"html\">", $feed); $stepTwo = explode("</content>", $stepOne[1]); $tweet = $stepTwo[0]; $tweet = str_replace("<", "<", $tweet); $tweet = str_replace(">", ">", $tweet); return $tweet; } $last_tweet = get_option('last_tweet'); if (!$last_tweet || time() - $last_tweet['time'] > 600) { //every 10 minutes $twitterFeed = @file_get_contents($feed); if ($twitterFeed) { $last_tweet = array('time' => time(), 'tweet' => stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix)); } else { if (!isset($last_tweet['tweet'])) { $last_tweet['tweet'] = ''; } $last_tweet['time'] = time(); } update_option('last_tweet', $last_tweet); } echo $last_tweet['tweet']; ?> PHP: