How can I get PHP to use the same APC cache when invoked on the CLI and the web?

倖福魔咒の 提交于 2019-12-08 15:27:01

问题


I'm using APC to cache user variables (with the apc_store/apc_fetch commands). I've also enabled APC for the CLI with the option "apc.enable_cli = 1". However, the CLI version of PHP seems to access a different APC cache from the version used by Apache.

Is it possible to configure APC to use the same cache for both CLI and web invocations?


回答1:


Not possible.. The only way to accomplish something like what your asking is to use something like memcacheD. Or run what you need to run through your webserver. What's running CLI that you cannot run via a web script with a cronjob?




回答2:


You can use shm. This technology lend to access to Unix Shared memory. You can put some variable in shm and then in another scritp, even programmed in another languaje you can get the shared variables.

shm_put_var and shm_get_var.

It's slower than APC, but it's faster than memcached, redis, etc.

I hope It will help you, and I'm sorry for my English....




回答3:


call your CLI as a CGI /path-to/cgi-sys/php5.cgi /home/name/crons/engine.php




回答4:


you would need a web server written in php -- the APC cache is shared only by forked child processes. If you had a php webserver, you could start a master cli, init apc, fork and load/run the web server in one child process, and fork and run your php cli script in another. Kind of a gross hack, huh. Fork and require(), I don't think the apc cache would survive an exec()



来源:https://stackoverflow.com/questions/439262/how-can-i-get-php-to-use-the-same-apc-cache-when-invoked-on-the-cli-and-the-web

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!