I've been having some significant server-side performance issues with an ExpressionEngine / CartThrob site (pages taking 5 seconds or more to generate under no load). Today I installed XDebug and WebGrind to take a look at what was causing the performance hit.

To my surprise, the biggest offender by far (taking over 3 seconds to run only 40 times), was the function CI_Encrypt->encode, and specifically CI_Encrypt->_xor_encode (taking about 97% of that time).

Nothing else in the profiler even comes close to taking this much time, so it looks like this function is basically the sole cause of my woes. Is there any way to speed it up?


From looking at the CI_Encrypt source code, I noticed that _xor_encrypt is only used when the PHP mcrypt module is not installed. I installed the PHP mcrypt module and added it to php.ini, which seems to have substantially reduced the time required to run this function.

Note: I'm still having some slowness due to this module (much less than before), particularly with CI_Encrypt->_add_cipher_noise, which I have posted about as a separate question here: How to improve performance of CI_Encrypt->_add_cipher_noise?

  • 1
    Nice job tracking that down! Can you post _add_cipher_noise() as a new question?
    – Anna_MediaGirl
    Dec 22 '13 at 19:30
  • 1
    I've moved the _add_cipher_noise follow-up here: expressionengine.stackexchange.com/questions/17913/…
    – Travis
    Dec 22 '13 at 23:06
  • i don't have cartthrob nor expresso, but i do hope they implement some sort of integrity check (hmac) on the decrypted data, because CI will not. CodeIgniter will just try to decrypt tampered-with strings and return whatever the result.
    – GDmac
    Dec 23 '13 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.