I have a php-system on PHP 7 which loads about 40 classes to work. It needs about 180ms to display a webpage, so I was starting to have a look if I could save some time by optimizing the code. I couldn't use a cache because the data shown on the page depends on which user is logged on and is highly individual.
I did some replacements, like using require instead of require_once and I replaced functions in loops like
for($i = 0; $i < $this->GetItemCount(); $i++)
with:
$len = $this->GetItemCount();
for($i = 0; $i < $nLen; $i++)
but - to my suprise - this only gets me a 4-5ms better result.
I then just made some experiments with microtime() to see where the time is consumed. It seems that just including and parsing all the classes takes about 120ms - and the work which is done then only consumes about 60ms.
I thought that including might be the problem so I put all the code in one big file - but that didn't help very much.
So it seems that the parsing/compiling is still very slow even with PHP 7. I had a look which possibilities there are to pre-compile the code to get better results, but it seems that solutions like APC or OPCache is only working when you have access to the server. I mostly use shared-hostings, so the question is: Are there any possibility to "compile" the php to bytecode which could be processed faster? I understand that it's tricky in shared hosting because the compiled code couldn't be stored in memory, but I don't understand why there doesn't seem to be a compiler which compiles the php-file to a byte-code file which could be read in less time then doing all the parsing again and again.