-4

I have a php application which provides restful service,I want to speed it by xcache,but the situation is not as imagined.

My php application bases on yii 1.1,and the function I test does heavy db query and calculation.The elapsed time if not use xcache is 600ms(300ms db query) and things are on the whole the same if use xcache.

I can see xcache is really working by accessing xcache admin page.

Xcache can save time by avoiding creating reduplicated opcode,theoretically it can speed my application,but it doesn't here,so can someone explain?

Nick
  • 1
  • 3
  • Op code cache speeds up the compilation step, nothing else. It does not reduce the time taken to actually run the op codes, or do any IO stuff. – Steve Jun 16 '16 at 11:04
  • opcode caching eliminates the parsing/lexing (compilation) time for the code itself, but isn't going to make any difference to database queries, or of actually executing the heavy calculation in your PHP code – Mark Baker Jun 16 '16 at 11:04
  • the testing was done by curl command,so it should contain the time of compilation. – Nick Jun 16 '16 at 12:03
  • Why should a curl request contain the compilation time for a PHP script? curl is language agnostic – Mark Baker Jun 16 '16 at 13:57
  • When we request a url by curl,web server first compile the php script,run it and response to the requestor,so the compilation time is contained.Pls correct if any thing wrong. – Nick Jun 16 '16 at 15:22
  • Yes, compilation time is included in the total time for the request, and is a very tiny proportion of the overall time compared with the execution of the script/retrieving data from database/etc – Mark Baker Jun 16 '16 at 18:24
  • Yes,so I can figure out the reason why xcache doesn't speed up my application now,script executing and db query occupy large proportion of the whole time. – Nick Jun 17 '16 at 02:57
  • That's right.... opcaching saves a fraction of a percentage of the overall execution time for the script.... it can make a big difference for lightweight script, but is negligeable when used with computation-intensive or I/O heavy scripts – Mark Baker Jun 17 '16 at 18:33

4 Answers4

0

You should try enable opcache in php ini that is now bundled in as part of php core. a better alternative would be to try and optermise the heavy query

James Kirkby
  • 1,716
  • 5
  • 24
  • 46
0

Profile your application. You can't expect a significant speedup if the bottleneck is IO or some poorly optimized DB queries.

Shira
  • 6,392
  • 2
  • 25
  • 27
0

Opcache is now the standard, and it's highly recommended to use it.

It's also seemless, you don't need to do a thing (other than installing it) as Opcache manages all the setting and getting of Op Code caches for you transparently.

Alternatively, you could attempt to diagnose your query by looking at database indexes, using EXPLAIN (if you're using MySQL) and caching the results.

Matt Cavanagh
  • 518
  • 5
  • 19
0

I think the reason is that compilation time only the small part of the whole.I'll test it and put the result here later.

Nick
  • 1
  • 3
  • I have done another test just now,in this scenario I just put some simple commands like echo and so on, and surely,xcache speed up the application by three times. – Nick Jun 17 '16 at 03:01