Jump to content

php code problem from command line?


shams

Recommended Posts

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.