Topic: PHP Performance Problem

I found that having include configuration files in the php files is very inefficient.

I found the solution here using PHP Cache and want to share it with everyone, I hope that you can find it useful.

Cache a variable in the data store .

<?php
$bar = 'BAR';
apc_store('foo', $bar);
var_dump(apc_fetch('foo'));
?>

You can store any data type, object, etc.

Read more:

http://www.php.net/apc

Re: PHP Performance Problem

klertiv wrote:

Я только недавно нашел нормальный учебник по С++, а так постоянно мучался.

---------------------------------------------
люблю смотреть сериал Ранетки  (прямо онлайн)

Post deleted. Write in English please

3

Re: PHP Performance Problem

Scripted wrote:

I found that having include configuration files in the php files is very inefficient.

I found the solution here using PHP Cache and want to share it with everyone, I hope that you can find it useful.

Cache a variable in the data store .

<?php
$bar = 'BAR';
apc_store('foo', $bar);
var_dump(apc_fetch('foo'));
?>

You can store any data type, object, etc.

Read more:

http://www.php.net/apc

Not everyone has an accelerator/cache, (or even APC specifically), installed. smile Also, it would be best to post a complete and working code block for future reference, just incase anyone does wish to use this method. Plus, do you have any figures regarding operational time differences between using includes and using the accelerator/cache?

4 (edited by Scripted 2009-06-03 14:12)

Re: PHP Performance Problem

In a small website, the differences are very small but here is an article for facebook and the comparison is:
Normal 4050ms
APC 135ms


full details:
http://sizzo.org/wp/wp-content/uploads/ … ing-dc.pdf


This piece of code is a complete reference, i'm not sure what else do you want to know.  So as the result, APC_STORE acts like Hashtable (C#, NET) or HashMap<String, Object> in JAVA.  Everything stores in the cache memory, it clears on startup & shutdown.

To store a variable in a memory you do:
apc_store('variableNameHere', $valueHere);

Read a variable:
apc_fetch('variableNameHere');

5

Re: PHP Performance Problem

Scripted wrote:

This piece of code is a complete reference, i'm not sure what else do you want to know.

Personally, nothing. smile Any half capable coder will know exactly what to do with that code you posted. I meant that it may be better to provide a fuller solution for those who are not as familiar with PHP as yourself. For example, checking to see whether certain variables are already cached or not and caching them if not, including files and caching their contents etc.

6 (edited by Scripted 2009-06-03 21:01)

Re: PHP Performance Problem

Matt ... I agree with you,  but I feel like every program startups differently.

Some store data in XML file, mySQL database, and others in text.

So it's hard to capture them alll ... I think understanding the concept is main key here.

A sample prototype can be something like this:

function onApplicationStartUp() {   
     if (!apc_fetch('isContainingData')) {
        initAllVariablesAndConnectionSettings();
   
       apc_store("isContainingData", true);
    } 
}

function initAllVariablesAndConnectionSettings() {
    // Your code here !!! loads from XML mySQL database  file ... what so ever!
   // I personally like to store my ettings in XML file because I can move the settings between programming languages.
}