Title: PHP error after updating PHP version
Last modified: April 14, 2021

---

# PHP error after updating PHP version

 *  Resolved [sarahjadesigns](https://wordpress.org/support/users/sarahjadesigns/)
 * (@sarahjadesigns)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/php-error-after-updating-php-version/)
 * I saw a warning on my dashboard about how I’m using an insecure version of PHP(
   5.6) and should upgrade to at least 7.4. When I did, I got PHP errors all over
   my site, but most were fairly easy to fix – mostly some single quotes missing.
 * There’s one I haven’t been able to crack. My site uses both Facebook and WP comments,
   so I have a function to consolidate and display the total count. This is the 
   error I’m getting at the bottom of each post where this should display:
 * `Warning: file_get_contents('https://graph.facebook.com/?ids=' . http://lucky-
   stars.ca/ptp/oatmeal-squares/): failed to open stream: No such file or directory
   in /home/luckysta/public_html/wp/wp-content/themes/yum/functions.php on line 
   513`
 * The relevant snippet of code from functions.php follows:
 *     ```
       function full_comment_count() {  
       global $post;  
       $url = get_permalink($post->ID);  
   
       $filecontent = file_get_contents('https://graph.facebook.com/?ids=' . $url); // This is line 513 referred to in the error
       $json = json_decode($filecontent);  
       $count = $json->$url->comments;  
       $wpCount = get_comments_number();  
       $realCount = $count + $wpCount;  
       if ($realCount == 0 || !isset($realCount)) {  
           $realCount = 0;  
       }  
       return $realCount;  
       }
       ```
   
 * Does anyone know what the issue is here? I’m guessing it’s just some incorrect
   nomenclature/formatting of PHP or somesuch, but my knowledge of this coding language
   is very limited. Note that I reverted back to PHP 5.6 while I troubleshoot this,
   so the error with not currently be visible on my site.
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fphp-error-after-updating-php-version%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 11 replies - 1 through 11 (of 11 total)

 *  [Joy](https://wordpress.org/support/users/joyously/)
 * (@joyously)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/php-error-after-updating-php-version/#post-14319444)
 * It seems like it’s the configuration of your PHP. The 5.6 version is set to allow
   fopen wrappers and 7.4 is not? Read [https://www.php.net/manual/en/function.file-get-contents.php](https://www.php.net/manual/en/function.file-get-contents.php)
 *  Thread Starter [sarahjadesigns](https://wordpress.org/support/users/sarahjadesigns/)
 * (@sarahjadesigns)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/php-error-after-updating-php-version/#post-14320871)
 * I’m not sure what you mean [@joyously](https://wordpress.org/support/users/joyously/),
   the info at the top of the page you linked seems to indicate it works with versions
   5, 7 and 8. Even the changelog further down indicates as much.
 * But if I’m misinterpreting this, then what could I do to replace `file_get_contents()`?
 *  [Joy](https://wordpress.org/support/users/joyously/)
 * (@joyously)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/php-error-after-updating-php-version/#post-14322892)
 * Read the entire page, including the Note at the bottom which talks about fopen
   wrappers.
 *  Thread Starter [sarahjadesigns](https://wordpress.org/support/users/sarahjadesigns/)
 * (@sarahjadesigns)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/php-error-after-updating-php-version/#post-14334636)
 * Thanks [@joyously](https://wordpress.org/support/users/joyously/), I did read
   it. However, this bit and the supporting links about fopen wrappers are sort 
   of Greek to me, as I don’t know enough about PHP to code it from scratch. Is 
   the notion that I can just swap out `file_get_contents()` with `fopen()`, or 
   is there more I need to do here?
 *  [Joy](https://wordpress.org/support/users/joyously/)
 * (@joyously)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/php-error-after-updating-php-version/#post-14337588)
 * No, you shouldn’t need to change any PHP. You need to investigate the settings
   on your server to discover the difference between the two versions. You might
   have to ask your host, because they can have settings to turn off the fopen wrappers
   that your code relies on.
 *  Thread Starter [sarahjadesigns](https://wordpress.org/support/users/sarahjadesigns/)
 * (@sarahjadesigns)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/php-error-after-updating-php-version/#post-14344931)
 * Thanks for clarifying. I did have a look at the extensions in my cPanel, but 
   didn’t find anything similar to `zlib`, which is why I thought I maybe had initially
   misunderstood your link. I’ll get in touch with my host and see if they can help
   me get to the bottom of this.
 *  Thread Starter [sarahjadesigns](https://wordpress.org/support/users/sarahjadesigns/)
 * (@sarahjadesigns)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/php-error-after-updating-php-version/#post-14418689)
 * Looks like `zlib` was enabled on both with PHP [5.6](https://paste.websitehostserver.net/ZWxkYXIK_2021-04-21_03-26-57_2W6EdwZUec)
   and [7.4](http://lucky-stars.ca/info.php). I tried switching to version 8.0 to
   see if whatever issue had been resolved with that one, but that just gives me
   a big fat WordPress error and the site won’t load at all.
 * I’m completely at a loss for how to fix this. Any other insight would be appreciated.
    -  This reply was modified 5 years, 1 month ago by [sarahjadesigns](https://wordpress.org/support/users/sarahjadesigns/).
 *  Moderator [Ipstenu (Mika Epstein)](https://wordpress.org/support/users/ipstenu/)
 * (@ipstenu)
 * 🏳️‍🌈 Advisor and Activist
 * [5 years, 1 month ago](https://wordpress.org/support/topic/php-error-after-updating-php-version/#post-14422248)
 * [@sarahjadesigns](https://wordpress.org/support/users/sarahjadesigns/) You actually
   need to rewrite it and use the HTTP API.
 * In this case, you probably need [https://developer.wordpress.org/reference/functions/wp_remote_get/](https://developer.wordpress.org/reference/functions/wp_remote_get/)
   to get the data.
 * A number of hosts block getting file contents like that one external (non local)
   files, as a security measure.
 *  Thread Starter [sarahjadesigns](https://wordpress.org/support/users/sarahjadesigns/)
 * (@sarahjadesigns)
 * [5 years ago](https://wordpress.org/support/topic/php-error-after-updating-php-version/#post-14507001)
 * Thanks [@ipstenu](https://wordpress.org/support/users/ipstenu/). My skills with
   PHP pretty much only extend to be able to tweak things a tiny bit. When it comes
   to function building, I have a pretty fuzzy understanding.
 * Comparing your info on `wp_remote_get()` and `file_get_contents()`, I get the
   sense that the main difference is that the former allows you to fetch an external
   URL. Could I then just swap it like so?
 *     ```
       function full_comment_count() {  
       global $post;  
       $url = get_permalink($post->ID);  
   
       $filecontent = wp_remote_get('https://graph.facebook.com/?ids=' . $url);
       $json = json_decode($filecontent);  
       $count = $json->$url->comments;  
       $wpCount = get_comments_number();  
       $realCount = $count + $wpCount;  
       if ($realCount == 0 || !isset($realCount)) {  
           $realCount = 0;  
       }  
       return $realCount;  
       }
       ```
   
 * Or is there more I need to do with `wp_remote_get()` to get a combined count 
   of Facebook and WordPress comments for a post?
 *  Moderator [Ipstenu (Mika Epstein)](https://wordpress.org/support/users/ipstenu/)
 * (@ipstenu)
 * 🏳️‍🌈 Advisor and Activist
 * [5 years ago](https://wordpress.org/support/topic/php-error-after-updating-php-version/#post-14508172)
 * Something like that. The details depends on Facebook and how it returns content.
   I haven’t looked deeply at that part.
 *  Thread Starter [sarahjadesigns](https://wordpress.org/support/users/sarahjadesigns/)
 * (@sarahjadesigns)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/php-error-after-updating-php-version/#post-14638103)
 * Finally had the chance to look into this. It wasn’t enough to swap `file_get_contents()`
   with `wp_remote_get()` – this would give an error about the line below with `
   json_decode()` needing a string.
 * By wrapping `$filecontent` on that line in `wp_remote_retrieve_body()` (thanks
   Google!), the code now works. Full function below.
 *     ```
       function full_comment_count() {  
       global $post;  
       $url = get_permalink($post->ID);  
   
       $filecontent = wp_remote_get('https://graph.facebook.com/?ids=' . $url);
       $json = json_decode(wp_remote_retrieve_body($filecontent)); 
       $count = $json->$url->comments;  
       $wpCount = get_comments_number();  
       $realCount = $count + $wpCount;  
       if ($realCount == 0 || !isset($realCount)) {  
           $realCount = 0;  
       }  
       return $realCount;  
       }
       ```
   

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘PHP error after updating PHP version’ is closed to new replies.

## Tags

 * [Comments](https://wordpress.org/support/topic-tag/comments/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Everything else WordPress](https://wordpress.org/support/forum/miscellaneous/)
 * 11 replies
 * 3 participants
 * Last reply from: [sarahjadesigns](https://wordpress.org/support/users/sarahjadesigns/)
 * Last activity: [4 years, 11 months ago](https://wordpress.org/support/topic/php-error-after-updating-php-version/#post-14638103)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
