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

4

11

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?

Uric answered 13/1, 2009 at 15:5 Comment(0)
S
11

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?

Stilwell answered 13/1, 2009 at 21:44 Comment(5)
.. or more importantly - why do you need that kind of performance optimisation on a cli script?Trihedron
Very true.. web is typically high impact/hits, and CLI one off calls.Stilwell
I'm not bothered about APC caching the CLI script. I want to be able to access the same APC user cache from the web and CLI. If it isn't possible I'll just have to call a web script from the CLI and get it to pass in the required data. Not the most elegant solution!Uric
The use case that lead me to go looking for the answer to this very question was that the APC cache in apache stores a compute complex data structure (it takes a few seconds to pull all the data from the db and shuffle it around into the structure that we access) that is used to speed up a bunch of pages. I have a long lived script that monitors memcached for hints on when to update that structure. Basically this is a local cache of memcache. (crazy as that seems, when you hit mega scale the on the wire time to fetch a big static object from memcache becomes unacceptable for every hit.)Cunnilingus
@Cunnilingus not crazy at all, APC is orders of magnitude faster than memcache due to the round trips.Fixation
F
4

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....

Floating answered 6/12, 2012 at 19:59 Comment(0)
U
1

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

Uziel answered 30/7, 2009 at 17:29 Comment(2)
Good idea, but this didn't work for me on CentOS (/usr/bin/php-cgi)Papert
This would only work if you're running PHP as (fast)CGI, not with mod_php in Apache (since APC is within the Apache processes' memory).Allodium
H
0

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()

Heterozygote answered 2/12, 2014 at 0:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.