1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Do "Notice" and "warnings" slow a PHP script, with no error reporting?

Discussion in 'PHP' started by JEET, Nov 10, 2019.

  1. #1
    Do "Notice" and "warnings" slow a PHP script, with no error reporting?

    I once did a test for this, and the difference in execution time was negligible.
    I am still curious though.
    SEMrush
    If error_reporting is set to zero, and "notice" errors are getting generated, does it matter much?

    This code for example will generate NOTICE errors:
    
    <?php
    
    $a=array( 'red'=>255, 'green'=>200, 'blue'=>100 );
    echo $a[red].'<br />'; //Notice error
    echo $a['green'].'<br />'; //notice error
    echo $a["blue"].'<br />'; //no error
    ?>
    
    Code (markup):
     
    JEET, Nov 10, 2019 IP
    SEMrush
  2. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,251
    Likes Received:
    26
    Best Answers:
    7
    Trophy Points:
    150
    #2
    I would say yes. Notices and Errors point to code that isn't quite working as expected. I always try to have no error_log present. If the error_log file shows up I always tend to fix the issues asap.
     
    stephan2307, Nov 11, 2019 IP
    sarahk and JEET like this.
  3. JEET

    JEET Well-Known Member

    Messages:
    2,417
    Likes Received:
    132
    Best Answers:
    3
    Trophy Points:
    185
    #3
    Let me run a test again, Will post findings. Last time I did, I did with a small script.
     
    JEET, Nov 11, 2019 IP
  4. JEET

    JEET Well-Known Member

    Messages:
    2,417
    Likes Received:
    132
    Best Answers:
    3
    Trophy Points:
    185
    #4
    Ran this test.

    Proper code, no errors generated.
    
    <?php
    //error_reporting(0);
    $s=time();
    $a=array( 'red'=>255, 'green'=>126, 'blue'=>50 );
    for($x=0; $x<5000; ++$x){
    echo $a["red"]."\n";
    }
    $e=time();
    echo '<h3>'. ($e-$s).'</h3>';
    ?>
    
    Code (markup):
    Time taken is "0" seconds. ($e-$s)

    Now with error_reporting to zero, and code which will generate notice error

    
    <?php
    error_reporting(0);
    $s=time();
    $a=array( 'red'=>255, 'green'=>126, 'blue'=>50 );
    for($x=0; $x<5000; ++$x){
    echo $a[red]."\n";
    }
    $e=time();
    echo '<h3>'. ($e-$s).'</h3>';
    ?>
    
    Code (markup):
    Time taken is again "0" seconds

    If I comment error_reporting line in second code, then each time $a[red] is accessed, a notice error was generated.
    Even then execution time was just "1" second...
    And with all those NOTICE lines in browser, 5000 times, both Firefox and chrome hanged. Only IE worked.

    But with error_reporting set to zero, it was "0" seconds in both cases, and no NOTICE errors thrown to browser.
     
    JEET, Nov 11, 2019 IP
  5. SpacePhoenix

    SpacePhoenix Well-Known Member

    Messages:
    129
    Likes Received:
    15
    Best Answers:
    1
    Trophy Points:
    120
    #5
    Just ran that in both Chrome and Firefox (with the error_reporting line commented out - have got error turned on by default), neither of them hung. Can't test in Edge as i've uninstalled that
     
    Last edited: Nov 11, 2019
    SpacePhoenix, Nov 11, 2019 IP
    JEET likes this.
  6. JEET

    JEET Well-Known Member

    Messages:
    2,417
    Likes Received:
    132
    Best Answers:
    3
    Trophy Points:
    185
    #6
    Well, I am getting 5000 lines of Notice errors thrown in browser and both browsers hung.

    Anyways, that is not the issue. The issue is whether PHP processing takes longer or not.
    There was no difference in both codes with error_reporting set to zero.
     
    JEET, Nov 11, 2019 IP