The most expensive operations in PHP?

What are some of the most expensive operations in PHP? I know things like overusing the @ operator can be expensive. What else do you think?

+5
source share
10 answers
  • serialize () is slow, like eval (), create_function (), and spawns additional processes through system () and related functions.
  • beware that APC cannot cache - conditional includes , eval () ed code, etc.
  • Opening database connections. Always cache your connections and reuse them.
  • object cloning
  • . , , . str_replace() preg_replace(), .
  • - .

, , :

  • ,
  • , .
  • , . : echo 'How are you ',$name,' I am fine ',$var1 , echo 'How are you '.$name.' I am fine '.$var1
  • . , , PHP .
+18

, , , . xDebug , , , , . WinCacheGrind ( ).

+5
 "Hello $name"

,

'Hello ' . $name

__get() __set() __call() ..

, , structures SPL

+4

, - , -, , .

( CPU, )

+2

, SQL . :

foreach ($db->query('SELECT * FROM categories') as $cat)
{
    foreach ($db->query('SELECT * FROM items WHERE cat_id = ' . $cat['cat_id']) as $item)
    {
    }
}

:

$sql = 'SELECT c.*, i.*
          FROM categoriess c
     LEFT JOIN items i USING (cat_id)
      ORDER BY c.cat_order';

foreach ($db->query($sql) as $row)
{
}
+1

curl_exec() , . , str_ * , .

+1
  • json_encode ,
  • , implode

, @, , , .

: http://www.php.net/manual/en/language.operators.errorcontrol.php#102543

, @ , . script ( @) 1,75 , ... script.

, , , , , @ .005 . , , @.

real 0m7.617s 0m6.788s sys 0m0.792s

vs

 

real 0m13.333s 0m12.437s sys 0m0.836s

"" , , .

+1

foreach() , , ; , php.

, , JS , . =/

0

- echo. , , !

x10, . , ?

0

uniqid()stupidly expensive. Do not use to generate many unique identifiers.

0
source

All Articles