Reputation: 4136
I am setting an APC cached array with the command:
apc_add( 'ips', $ips );
Via the command line. This cached array can be retrieved with:
apc_fetch( 'ips' )
in the same script.
However, it cannot be accessed from either subsequent CLI scripts or via PHP called by Apache. While I can call variables across scripts ran by Apache.
I am running on: 5.4.6-1ubuntu1.8 and APC is enabled with:
apc.enable_cli=1
On my local PC, I am using APCU with PHP7 and this problem does not occur.
Settings:
apc.cache_by_default => On => On
apc.canonicalize => On => On
apc.coredump_unmap => Off => Off
apc.enable_cli => On => On
apc.enabled => On => On
apc.file_md5 => Off => Off
apc.file_update_protection => 2 => 2
apc.filters => no value => no value
apc.gc_ttl => 3600 => 3600
apc.include_once_override => Off => Off
apc.lazy_classes => Off => Off
apc.lazy_functions => Off => Off
apc.max_file_size => 1M => 1M
apc.mmap_file_mask => no value => no value
apc.num_files_hint => 1000 => 1000
apc.preload_path => no value => no value
apc.report_autofilter => Off => Off
apc.rfc1867 => Off => Off
apc.rfc1867_freq => 0 => 0
apc.rfc1867_name => APC_UPLOAD_PROGRESS => APC_UPLOAD_PROGRESS
apc.rfc1867_prefix => upload_ => upload_
apc.rfc1867_ttl => 3600 => 3600
apc.serializer => default => default
apc.shm_segments => 1 => 1
apc.shm_size => 32M => 32M
apc.shm_strings_buffer => 4M => 4M
apc.slam_defense => On => On
apc.stat => On => On
apc.stat_ctime => Off => Off
apc.ttl => 0 => 0
apc.use_request_time => On => On
apc.user_entries_hint => 4096 => 4096
apc.user_ttl => 0 => 0
apc.write_lock => On => On
Any ideas?
Upvotes: 3
Views: 799
Reputation: 15361
Yes this is a confusing aspect to the apc.enable_cli=1 parameter. It suggests that you could get behavior similar to the way it might work with an apache module.
However, with cli, there is one process and no shared state, so despite the fact that the parameter exists once the first cli execution is complete, the entire apc memory space is disposed of and ceases to exist when the cli script is complete.
You need some other mechanism (memcache, redis, queues, flat file, database) to make this work with multiple CLI executions (batch runs?) other than APC.
FWIW, APC uses shared memory for those operations. There is a seperate shared memory api for php, which might work. The use case for this is for something shared between processes that by definition are confined to one single server. There aren't a lot of those use cases I can think of. Using those routines with CLI might work, but I haven't tried them.
If you really need something shared, that would even work across multiple servers (for example a cluster of batch processing workers) then you are better off with queuing, memcache or redis.
Upvotes: 4