M
M
MIK Ek2016-07-13 10:30:49
PHP
MIK Ek, 2016-07-13 10:30:49

How to disable compile code in php?

There is a big cycle, on the test north it should display information, on the production it is easy to execute (as quickly as possible).

$debug=false;
$r=$f=0;
for ($i=1;$i<1000000000;$i++)
{
    $r+=$i;

//debug info
    if ($debug AND $i%1000000){
        echo $r . PHP_EOL;
    }
//debug info end

    $f*=$i+$i;

//debug info
    if ($debug AND $i%2000000){
        echo $f . PHP_EOL;
    }
//debug info end
}

Can I somehow throw out the debug info blocks from the production version? After all, even a simple Boolean check for 1kkk iterations can greatly slow down the process
. somehow replace the condition at the execution level with conditions at the compilation level.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2016-07-13
@MIKEk8

If you have Opcache enabled and configured, then dead code is removed automatically: https://bugs.php.net/bug.php?id=71102

A
Andrey Pavlenko, 2016-07-13
@Akdmeh

1) Leave everything as it is. To do this, make a simple time test, run it several times - I think even 1 billion simple checks will not really affect performance in any way
2) If it does so that it seems fundamental (which I doubt) - create two versions of the loop - with debug and without. Maybe this is not very good in terms of code cleanliness, but nothing else comes to mind
3) The problem here is even different - the script is very voracious, so an extra check will not play any role

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question