PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 6, 2022

[FIXED] PHP Heroku - Call undefined function mb_detect_encoding()

 January 06, 2022     composer-php, heroku, php     No comments   

Issue

I'm trying to deploy a PHP project to Heroku. I use composer with to install slim framework and simple_http_dom dependencies. Here content of my composer.json:

{
    "require": {
        "slim/slim": "2.4.3",
        "shark/simple_html_dom": "dev-master"
    }
}

when I run the app locally, it's working fine. Then I tried to push it to Heroku, and it seems successful, I saw no error message.

However, there is a problem when I tried to access it from the browser. nothing shows up. Below is the log from heroku logs command.

[Sun Aug 31 00:14:37.566291 2014] [proxy_fcgi:error] [pid 60:tid 140467698300672] [client 10.2.162.208:58783] AH01071: Got error 'PHP message: PHP Fatal error:  Call to undefined function mb_detect_encoding() in /app/vendor/shark/simple_html_dom/simple_html_dom.php on line 1234\n', referer: http://myapp.herokuapp.com/index.php/scrap/all
[31/Aug/2014:00:14:37 +0000] "POST /index.php/scrap/all/do HTTP/1.1" 500 - "http://myapp.herokuapp.com/index.php/scrap/all" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36"
[31-Aug-2014 00:14:37] WARNING: [pool www] child 58 said into stderr: "NOTICE: PHP message: PHP Fatal error:  Call to undefined function mb_detect_encoding() in /app/vendor/shark/simple_html_dom/simple_html_dom.php on line 1234"

One piece from the error that might be interesting:

Got error 'PHP message: PHP Fatal error:  Call to undefined function mb_detect_encoding() in /app/vendor/shark/simple_html_dom/simple_html_dom.php on line 1234\n', referer: http://myapp.herokuapp.com/index.php/scrap/all

This is the first time I got the above error. I have another app running on Heroku using the same dependencies (but without composer) and it's working fine, but this one isn't.

what should I do to fix this problem?


Solution

The problem is that the mbstring extension isn't enabled by default, see https://devcenter.heroku.com/articles/php-support#extensions

Just add ext-mbstring as a dependency to your composer.json so it looks like this:

{
    "require": {
        "ext-mbstring": "*",
        "slim/slim": "2.4.3",
        "shark/simple_html_dom": "dev-master"
    }
}

Heroku will then auto enable the extension when you git push.



Answered By - dzuelke
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing