Forum Moderators: coopster
i am interested in scalability as opposed to outright speed as our site can get quite busy at times.
with this in mind, which would be better coding practice? to use the native array_push() and array_walk() functions, or to use while() and for() loops, etc.
Example 1
while ($row = mysql_fetch_array($result)) {
$my_array[] = $row;
}
or
while ($row = mysql_fetch_array($result)) {
array_push($my_array, $row);
}
do the different ways of populating the array above have any difference in speed / resource optimisation?
Example 2
function my_function() {
.. define function
}
array_walk($my_array, 'my_function');
or
$a = sizeof($my_array);
for ($x = 0; $x < $a; $x++) {
...do stuff to $my_array[$x]
}
in the above example i assume that to declare a function and then array_walk() it would be a lot slower than using a for() loop.
aren't functions to be avoided unless it is code which is repeated more than twice - aren't they a real resource-eater?
cheers
and in both your example, i don't see any resource(except cpu resource) is different.
there's a lovely article with excellent links for further reading here [php.weblogs.com] which mentions (hope the URL is ok jatar_k)
zend
afterburner
PHPA
APC
i must say i am tempted to get the zend optimizer + accelerator (costs-money-must-be-good way of thinking but also because of the reliability ;-)
i was in quite a few forums and mailing lists for the other products in which server crashes and malfunctioning code were an issue.
would very much appreciate some real-life experiences.
cheers
p.s. thanks nick :-)