0

I am working on a phpwebsocket application. I have to store the instance of the phpwebsocket every where in my app. I found a solution, that beeing with APC. And it doesn't work. The problem is that if I acces a file with apc_store('foo', 'bar') from a script php that I run on php console, it won't work. If I do a http request (using a browser.. ) it actually works, but I realy have to run the phpwebsocket from php console.

In php.ini :

[APC]
extension=php_apc.dll
apc.enabled = 1
apc.enable_cli = 1 
apc.shm_segments = 1
apc.shm_size = 64M
apc.max_file_size = 10M
apc.stat = 1

Thanks.

ioan
  • 751
  • 1
  • 9
  • 26

2 Answers2

0

php-cli doesn't share the APC cache with php-cgi or php-fpm. In fact, I'm not sure it even shares the APC cache with itself!

In addition, you can't store resource/instances like streams or sockets inside APC - only serialized objects.

I would use http://memcached.org/ to cache data since then, when you add more servers, they will also be able to access the same cache. APC/XCache only works on a single server.

Xeoncross
  • 55,620
  • 80
  • 262
  • 364
  • I need a reference to a object that send data to my clients via other scripts. Every script need a way to comunicate with clients, so the scripts can send via websocket. Do you understand my problem? EDIT: I think that memcached is far away what I need. – ioan May 02 '12 at 18:37
0

APC collects and stores cache within its process space. Since console apps start a new process every time, APC cache starts clean and therefore there is no performance gain. In case of apache mod, the process space is apache web server itself which stays alive.

1) how about doing a wget URL on console instead of a standalone console php script? If you need output, use wget -O - URL. APC will work just fine. The restriction here is script does not get any physical file access.

2)You could do a file_get_contents(URL) from within your console php console script and dump the contents. That way, you can call it from console and even have the advantage of shared APC cache. You also get physical file access here but there is one problem. URL fetching as files are OFF by default for serious security reasons. You may need to turn it ON in php.ini. Carefully verify your case before using it on production network.

http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen

thevikas
  • 1,618
  • 1
  • 14
  • 31
  • That's awesome. I needed a way to keep a instante of a object between files. So I decided that APC is best solution, aparently it's not becouse I need the console for instantiate the instante of the object. Thanks! – ioan May 03 '12 at 05:14