error_log()calls until I figured out what was gumming up the works.
It turned out to be an
mcrypt_create_iv()call. Sometimes that call would run in a fraction of a second, and sometimes it would take over a minute, with no discernible pattern. I had pretty much done a copy-and-paste from the
mcrypt_module_open()manual page, which shows using the
MCRYPT_DEV_RANDOMconstant as the second argument to
mcrypt_create_iv(). It finally occurred to me to try using the
MCRYPT_DEV_URANDOMconstant (note the "U"), instead, and the encryptions immediately became consistently fast.
This was happening on a VMWare ESX guest running RHEL4. A Web search or two found a good comparison of
/dev/urandom, and my problem turned out to be a good illustration of
/dev/randomblocking the caller until sufficient entropy is attained.