My hosting company, by default, has display_errors set to On. Obviously, I don't want that on a production site. I can create a local php.ini file and upload it, but my understanding is it would not be effective unless the process was restarted, is that correct?

Would it be better to use an ini_set() directive in the scripts that are called? If so, does it need to be in every script, even those that are included by other scripts, or does it just need to be in the first script called? The manual doesn't say one way or the other.

<?php

// index.php
ini_set('display_errors', Off);

// does the ini_set directive need to be coded in all these included files also?
include('header.php');
include('another_script.php');
include('footer.php');

?>

    If your server (apache) supports .htaccess
    you can put many php ini values in such a file.
    Either in the web root, or in any sub directory.

    .htaccess has 2 types of directives for PHP
    php_flag settingname ON
    php_value settingname string/value

    php_flag can only be ON or OFF
    while
    php_value can be anything like a path or a number

    Here are what I use in my .htaccess for php ini settings and Errors
    at my php development & testing site
    .htaccess

    #30719 = E_ALL in PHP 5.3
    php_value error_reporting 30719
    php_value display_errors On
    
    php_flag log_errors On
    
    # logs all my PHP Errors to a textfile ('_phperr.txt') in current directory
    php_value error_log _phperr.txt
    
    #
      Pikachu2000 wrote:

      My hosting company, by default, has display_errors set to On. Obviously, I don't want that on a production site.

      No one should want that... makes me wonder about the competency of your hosting provider. :o

      Pikachu2000 wrote:

      I can create a local php.ini file and upload it, but my understanding is it would not be effective unless the process was restarted, is that correct?

      That's unlikely, since you presumably don't have access to restart the web server daemon (or is this a VPS/managed server solution and you do, in fact, have access?).

      I'm using Mediatemple, for example, and any chance in my php.ini file I make is reflected on a phpinfo() readout immediately.

      Pikachu2000 wrote:

      Would it be better to use an ini_set() directive in the scripts that are called? If so, does it need to be in every script, even those that are included by other scripts, or does it just need to be in the first script called?

      Think of including files as doing nothing more than copying-and-pasting the code from the included' script directly into the parent script (with a couple considerations, such as the PHP parser dropping into HTML mode as well as the fact that the included script gets included at the global scope level, even if you run include() inside of a function). In other words: only the parent script (the one that's doing the include()'ing) would need to set the directive.

      However...

      Pikachu2000 wrote:

      Would it be better to use an ini_set() directive in the scripts that are called?

      No, it wouldn't. While you could setup PHP to automatically include a file that calls [man]ini_set/man every time a PHP script is parsed, I still think it would be better to make this change in the php.ini file.

      If you had a parse error, for example, then the ini_set() would never be executed and PHP would display the error to the user (rather than logging it for later review, which I'm assuming you're planning on doing... right? 😉).

        bradgrafelman;10945380 wrote:

        No one should want that... makes me wonder about the competency of your hosting provider. :o

        You know, that's a great point. I think I'm going to call them on that, and see what it would take to get that changed globally.

        That's unlikely, since you presumably don't have access to restart the web server daemon (or is this a VPS/managed server solution and you do, in fact, have access?).

        I'm using Mediatemple, for example, and any chance in my php.ini file I make is reflected on a phpinfo() readout immediately.

        Think of including files as doing nothing more than copying-and-pasting the code from the included' script directly into the parent script (with a couple considerations, such as the PHP parser dropping into HTML mode as well as the fact that the included script gets included at the global scope level, even if you run include() inside of a function). In other words: only the parent script (the one that's doing the include()'ing) would need to set the directive.

        However...

        No, it wouldn't. While you could setup PHP to automatically include a file that calls [man]ini_set/man every time a PHP script is parsed, I still think it would be better to make this change in the php.ini file.

        If you had a parse error, for example, then the ini_set() would never be executed and PHP would display the error to the user (rather than logging it for later review, which I'm assuming you're planning on doing... right? 😉).

        Yes 🙂 I log everything, and use trigger_error() A LOT also.

          UPDATE: I just got off the phone with them. Their tech support told me the webservers reload every night, so I FTP'd a php.ini file. I guess I'll have to wait until tomorrow to see any effect it has . . .

            Write a Reply...