It is very difficult khổng lồ figure out what went wrong. I kết thúc up commenting out code, entering "echo" statements everywhere, etc. Trying to lớn narrow down the problem. But there surely must be a better way, right?
Is there a way lớn get PHP to lớn produce a useful error message, lượt thích Java does?
Bạn đang xem: Debug a php cli scriptphp debugging error-handling
edited Nov 19, 2019 at 18:58
21.1k5959 gold badges7373 silver badges9393 bronze badges
asked May 10, 2009 at 9:48
địa chỉ a bình luận |
41 Answers 41
Sorted by: Reset to mặc định
Trending sort available
Trending sort Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to lớn surface more up-to-date answers.
It falls back khổng lồ sorting by highest score if no posts are trending.Switch lớn Trending sort
Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)
For syntax errors, you need to enable error display in the php.ini. By default these are turned off because you don"t want a "customer" seeing the error messages. Kiểm tra this page in the PHP documentation for information on the 2 directives: error_reporting & display_errors. Display_errors is probably the one you want to lớn change. If you can"t modify the php.ini, you can also địa chỉ cửa hàng the following lines to lớn an .htaccess file:
php_flag display_errors onphp_value error_reporting 2039You may want to consider using the value of E_ALL (as mentioned by Gumbo) for your version of PHP for error_reporting khổng lồ get all of the errors. More info
3 other items: (1) You can check the error log tệp tin as it will have all of the errors (unless logging has been disabled). (2) Adding the following 2 lines will help you debug errors that are not syntax errors:
error_reporting(-1);ini_set("display_errors", "On");(3) Another option is to use an editor that checks for errors when you type, such as PhpEd. PhpEd also comes with a debugger which can provide more detailed information. (The PhpEd debugger is very similar lớn xdebug và integrates directly into the editor so you use 1 program to vị everything.)
Cartman"s link is also very good: http://www.ibm.com/developerworks/library/os-debug/