shams Posted September 18, 2018 Share Posted September 18, 2018 I need to run getmail with two php codes in a loop, i tried to run all these from the web browser but the php code cannot start the getmail i use the exec, shell_exec and system, now i decided to run these code from the gnome terminal, but i get the problem with the one of php code not running from the command line , this one is not running: <?php $val = apc_fetch('id'); $id=$val + 1; apc_store('id', $id, 0); $var = apc_fetch('id'); echo $var ?> the command i am running the php code is #php -f /home/user/wwww/example.net/apc.php any help please? Link to comment Share on other sites More sharing options...
requinix Posted September 18, 2018 Share Posted September 18, 2018 "Not running" doesn't say much. I'm confident the code really is running, and the problem is that it's not doing what you want it to do. We'll start easy: do you have apcu installed and enabled? Link to comment Share on other sites More sharing options...
shams Posted September 19, 2018 Author Share Posted September 19, 2018 i am running ubuntu 18.04 and the packages php-apcu php-apcu-bc are installed, these php codes working fine from the web browsers. should i install the apcu from github or it's sufficient? Link to comment Share on other sites More sharing options...
requinix Posted September 19, 2018 Share Posted September 19, 2018 Does php -m on the command line show that apcu is active? And no, if you installed it then you installed it. You don't need to go grab the sources. Link to comment Share on other sites More sharing options...
shams Posted September 20, 2018 Author Share Posted September 20, 2018 ~$ php -m | grep apc apc apcu Link to comment Share on other sites More sharing options...
requinix Posted September 20, 2018 Share Posted September 20, 2018 Then by all accounts it should run. Not necessarily do what you think it will, but it should run and output something. Unless... #php -f /home/user/wwww/example.net/apc.php The # isn't actually part of the command, right? Link to comment Share on other sites More sharing options...
shams Posted September 20, 2018 Author Share Posted September 20, 2018 no # is not of the command i put just for the bash prompt, this is the output when i run the apc.php from the firefox web browser: http://example.net/apc.php 1 prints the right ouput but from command line i didn't see any output. Link to comment Share on other sites More sharing options...
requinix Posted September 20, 2018 Share Posted September 20, 2018 Ah. Knew I was forgetting something important. Did you enable the apc.enable_cli setting? Link to comment Share on other sites More sharing options...
shams Posted September 20, 2018 Author Share Posted September 20, 2018 from where i should enable apc.enable_cli i searched in /etc/php/7.2 and in /etc/apache2 but didn't find that one? Link to comment Share on other sites More sharing options...
shams Posted September 20, 2018 Author Share Posted September 20, 2018 I enabled the apc.enable_cli from the /etc/php/7.2/apache2/conf.d/20-apcu.ini now when i run the apc.php from the command line it just prints the 1, in every load it should increase the id by plus one, which is doing from the web browser prints the 5? Link to comment Share on other sites More sharing options...
requinix Posted September 20, 2018 Share Posted September 20, 2018 Excellent: we've reached the "not necessarily do what you think it will" stage. The APC cache only lasts as long as the PHP process is running. From the command line, it executes your script and exits. The cache is destroyed. It's not practical, nor for the most part even reasonable, to use a memory-level cache (like APC) for command-line scripts. If you need something cached, and especially if you want that value shared between the command-line and web scripts, then you need another type of cache. A network-level cache, like Redis or Memcache. Link to comment Share on other sites More sharing options...
gizmola Posted September 20, 2018 Share Posted September 20, 2018 13 hours ago, requinix said: Excellent: we've reached the "not necessarily do what you think it will" stage. The APC cache only lasts as long as the PHP process is running. From the command line, it executes your script and exits. The cache is destroyed. It's not practical, nor for the most part even reasonable, to use a memory-level cache (like APC) for command-line scripts. If you need something cached, and especially if you want that value shared between the command-line and web scripts, then you need another type of cache. A network-level cache, like Redis or Memcache. Yes exactly. APC cache has no benefit for CLI because the cache is tied to each php process. For CLI scripts the php process gets created and destroyed on each excecution. If you want an in memory cache you need to use one of the old standby methods: memcached or Redis. Those also have the advantage of being independent of the application server, so they are inherently capable of working in a cluster. The other option is to use the shared memory functions Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.