0
votes

I am trying to use apc_store to store a token variable that would continously change, thus need to be created by one php script, and accessed by another php script.


Environment: PHP: version 7.3 OS: Ubuntu 18.04

References followed:

Stackoverflow: Troubleshooting apc_store

PHP Manual - apc_store


Installation procedure:

sudo apt-get install php-apcu
sudo apt-get install php-apcu-bc

Installation result:

php-apcu is already the newest version (5.1.18+4.0.11-1+ubuntu18.04.1+deb.sury.org+1).
php-apcu-bc is already the newest version (1.0.5-1+ubuntu18.04.1+deb.sury.org+20191129).

The problem

Even though I do not get an error message, the system will not return expected result, e.g. the string "abc", further on the result indicates "bool(false)" which should be "bool(true)".

Question:

How can I get the result to show?:

string(3) "abc"

Other tests I tried to change /etc/php/7.0/mods-available/apcu-ini to

extension=apcu.so
extension=apc.so

...giving the error:

PHP Warning:  Module 'apc' already loaded in Unknown on line 0

My php script:

<?php
$token = "abc";
apc_store('token_1', $token);
var_dump(apc_fetch('token_1'));

Result:

bool(false)

Expected result:

string(3) "abc"


Troubleshooting:

Checking apc:

Result:

$ php -i | grep apc

/etc/php/7.3/cli/conf.d/20-apcu.ini,
/etc/php/7.3/cli/conf.d/25-apcu_bc.ini
apc
apcu
apc.coredump_unmap => Off => Off
apc.enable_cli => Off => Off
apc.enabled => On => On
apc.entries_hint => 4096 => 4096
apc.gc_ttl => 3600 => 3600
apc.mmap_file_mask => no value => no value
apc.preload_path => no value => no value
apc.serializer => php => php
apc.shm_segments => 1 => 1
apc.shm_size => 32M => 32M
apc.slam_defense => Off => Off
apc.smart => 0 => 0
apc.ttl => 0 => 0
apc.use_request_time => On => On
1
are you running it from CLI? Can you try if it works through http request? - matiit
@matiit I am following the instructions from above mentioned "PHP apc_store" which creates a php file and I trigger the php file from a terminal. - Toolbox
Can you show the result of php -i | grep apc? I am guessing you have: apc.enable_cli => Off => Off - matiit
@matiit I updated the question. At the end you find the result of [php -i | grep apc]. - Toolbox
@matiit. Works now. When I breakout the [var_dump(apc_fetch('token_1))] to another file, I do get boo(false) but that is a separate concern. I will register another question for that. Will go ahead and approve below answer. - Toolbox

1 Answers

1
votes

You need to enable apc for cli.

Find out which php.ini file is loaded:

php -i | grep "Loaded Configuration File"

Edit above file and add:

apc.enable_cli=On

And try again.

Edit after question has been updated:

Just add above line to the following file: /etc/php/7.3/cli/conf.d/20-apcu.ini