Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6376073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:41:52+00:00 2026-05-25T01:41:52+00:00

i have a php script like this: <?php $likes = ‘https://graph.facebook.com/google’; $fb = file_get_contents($likes);

  • 0

i have a php script like this:

    <?php
$likes = 'https://graph.facebook.com/google';
$fb = file_get_contents($likes);
$fb_array=json_decode($fb,true);
$all_likes = $fb_array['likes'];
$english_format = number_format($all_likes);
?>

what happens sometimes is that the url is failing and i get something like this:

Warning: file_get_contents(https://graph.facebook.com/google) [function.file-get-contents]: failed to open stream: HTTP request failed! in /var/www/html/google/index.php on line 774

I was wondering if there is a way for the code to degrade gracefully, because is bringing my entire website down.

I was thinking if there is a php or curl alternative to handle that error.

any ideas?

Thanks

edit:
i could so this:

    <?php
$likes = 'https://graph.facebook.com/google';
if(!@file_get_contents($likes)){
    $english_format = 123;
} else {
$fb = file_get_contents($likes);
$fb_array=json_decode($fb,true);
$all_likes = $fb_array['likes'];
$english_format = number_format($all_likes);
    } 
?>

but it still slows down my website

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:41:53+00:00Added an answer on May 25, 2026 at 1:41 am

    You can handle HTTP errors with file_get_contents by using a stream context:

    $context = stream_context_create(array(
        'http' => array(
             'ignore_errors' => true,
        ),
    ));
    
    $fb = file_get_contents('http://www.google.com');
    $code = substr($http_response_header[0], strpos($http_response_header[0], ' ')+1);
    
    if ($code != 200) {
        // there might be a problem
    }
    

    Additionally, display_errors should be Off on production environments.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have PHP scrip that goes like this: if ($cost_frm < $cost){ echo <script
I have a action.php script from where I call a python script like this:
I have a regular expression in my PHP script like this: /(\b$term|$term\b)(?!([^<]+)?>)/iu This matches
I have been writting a keyword search script based on this tutorial: http://www.hackosis.com/2007/11/06/howto-simple-search-engine-with-php-and-mysql/ Like
I have a directory structure like the following; script.php inc/include1.php inc/include2.php objects/object1.php objects/object2.php soap/soap.php
I have a php script that i run via command line like php file.php
<?php session_start(); ... ?> <?php session_start(); ?> If I have some php script like
I have two different servers and a script like this: echo <div style=\some style\>whatever</div>;
i have script like this <html xmlns=http://www.w3.org/1999/xhtml> <head> <meta http-equiv=Content-Type content=text/html; charset=UTF-8 /> <title>Testing
Ok, so I have this PHP script that runs in a nice little infinite

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.