nrg_alpha Posted June 26, 2009 Share Posted June 26, 2009 Seems Google botched some PHP tips, as a PHP team member responded on Google Groups. I was aware about creating copies of variables not doubling memory due to this article. But Gwynne debunked it pretty quickly as well with the simple snippet test: $data = str_repeat("*", 512 * 1024); // synthesize 512K of data $memory_used_before = memory_get_usage(); $more_data = $data; $memory_used_after = memory_get_usage(); print "Before: {$memory_used_before}\nAfter: {$memory_used_after}\n"; The part of Google's suggestion about when using strings without variables, one should use single quotes as opposed to double quotes (due to the PHP interpreter having to scan through and replace variables with their values) is how I understood it. Turns out, Gwynne was right; PHP does indeed deal with strings without variables faster in double quotes instead of single quotes (take the example found at http://pastie.org/523023 and test it without variables involved). So that one admittedly threw me off somewhat. The Google article delves into more things (like switch/case vs if/else, echo vs print, etc..) But on the whole, seems Google opened mouth and is now about to insert foot. Quote Link to comment https://forums.phpfreaks.com/topic/163773-googles-php-performance-tips/ Share on other sites More sharing options...
ober Posted June 26, 2009 Share Posted June 26, 2009 Interesting find. Thanks for the info. Quote Link to comment https://forums.phpfreaks.com/topic/163773-googles-php-performance-tips/#findComment-864135 Share on other sites More sharing options...
nrg_alpha Posted June 26, 2009 Author Share Posted June 26, 2009 No problem. I found this initially over at sitepoint. I have now noticed responses to that sitepoint article. If you read Wardrop's comment, this user clarifies what the Google author was perhaps trying to get at. Quote Link to comment https://forums.phpfreaks.com/topic/163773-googles-php-performance-tips/#findComment-864155 Share on other sites More sharing options...
gevans Posted June 26, 2009 Share Posted June 26, 2009 I just had a look at the article/videos and the response from the php team. I've always been a strong follower of many google apps, and enjoy watching their efforts to change the web to the better. It seems this time they messed up... royaly! As usual I like their outlook, the idea of a colaborative effort to speed up the web, it's just unfortunate that they let someone push out suggestion with no knowledge of the working of php. I'm not a person who's looked into the inner workings of php, and it's use of different C syntax (and other lagnauges) and how similar functions compare, but I never claimed to. It looks like they've asked a sheep to talk about a sheppard. Quote Link to comment https://forums.phpfreaks.com/topic/163773-googles-php-performance-tips/#findComment-864170 Share on other sites More sharing options...
.josh Posted June 26, 2009 Share Posted June 26, 2009 hahaha LOL damn... it would have been one thing for average Joe programmer to step in and say that but for someone from php.net to say that. ULTIMATE BURN. LOL I mean, what can you say to that? "Er...umm...shit." Open mouth, insert foot indeed! I'm not going to ostracize the article poster though. His heart is in the right place. Quote Link to comment https://forums.phpfreaks.com/topic/163773-googles-php-performance-tips/#findComment-864174 Share on other sites More sharing options...
nrg_alpha Posted June 26, 2009 Author Share Posted June 26, 2009 Well I noticed Eric Chiggins (the Google author in question) has responded to Gwynne (within the Google Groups link), stating that those tips were for older PHP installations (v 3 & 4). Makes me wonder out lout if this is merely to save face in public. While I can see that there are hosting providers out there running older versions of PHP, I find it odd that after PHP 5 has been out for how long now, the advice wouldn't be geared towards modern PHP. Gwynne did state that those points (to some degree) were true in older versions, but is no longer the case nowadays (and add to this how PHP is configured might still not hold true even today). It will be interesting to see the modifications Eric makes to his article (as he plans to amend it). I have seen the backlash on sitepoint, with comments geared towards the fact that since this is on behalf of Google, they really ought to be much more clear / concise when writing these things (due to people at large trusting what Google puts out there). So it could be largely just a matter of miss communication.. in either case, perhaps this will make Googles more cautious in the future about what exactly they put into their articles. Quote Link to comment https://forums.phpfreaks.com/topic/163773-googles-php-performance-tips/#findComment-864189 Share on other sites More sharing options...
.josh Posted June 26, 2009 Share Posted June 26, 2009 Well I noticed Eric Chiggins (the Google author in question) has responded to Gwynne (within the Google Groups link), stating that those tips were for older PHP installations (v 3 & 4). Makes me wonder out lout if this is merely to save face in public. That's exactly how I interpreted his response, too, LOL. Lame attempt to save face. Even though Gwynne did acknowledge issues for previous versions of php, he was also quick to point out that a) they MIGHT come up, depending on how you have a million diff things setup, b) even then it is not anything to shake a stick at. So overall, lame attempt to save face. Quote Link to comment https://forums.phpfreaks.com/topic/163773-googles-php-performance-tips/#findComment-864201 Share on other sites More sharing options...
corbin Posted June 27, 2009 Share Posted June 27, 2009 What the Google guy was trying to get at was entirely wrong*, but the example snippet of code he supplied was actually an example where it would double memory usage.... $description = strip_tags($_POST['description']); $description and $_POST['description'] are no longer equal. (Well, they could be, but they still wouldn't be to PHP as far as memory management goes.) But, then he had to go and echo something, entirely invalidating his point. echo strip_tags($_POST['description']); Obviously the data returned from the strip_tags has to exist in memory, if just briefly. So yeah, I guess he did straight up screw up there, but just his first part would've doubled memory (as would his second... but he didn't realize that.) *I think what he was getting at was that: $var = 'hi'; $val = $var; Would double memory. Quote Link to comment https://forums.phpfreaks.com/topic/163773-googles-php-performance-tips/#findComment-864569 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.