register_globals and performance

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

register_globals and performance

Post by scorphus »

Hi,

If "register_globals" is enabled in php.ini, PHP have to make a copy for global var. Beyond unsafe it affects the performance of the PHP. But how much performance do one lose setting it this way?

Thanks for your time.

Regards,
Scorphus.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Not sure, but I hardly think that the performance difference between the two would be drastic...

You could test it by:

Code: Select all

<?php
function getmicrotime(){ 
    list($usec, $sec) = explode(" ",microtime()); 
        return ((float)$usec + (float)$sec); 
    } 
    $time_start = getmicrotime();
?>
<form methof="post">
<input type="submit">
<?php
for ($i=1;$i<2000;$i++) {
    echo '<input type="text" name="somename[]" value="Current val: '.$i.'">';
}
?>
</form>
<?php
    $time_end = getmicrotime();
    $time = $time_end - $time_start;
    echo "Took $time seconds";
?>
...or something after rewriting it, and then try submitting it with and withought register_globals...
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Nothing you'd notice.

In any case, reg globs should always be off for security reasons - if you have the choice.
Post Reply