≡ Menu

PHP: Disable APC Module At Command Line CLI Scripts / Cron Scripts

I have a PHP application developed and running on LAMP. I have APC installed on the server. APC is a free, open, and robust framework for caching and optimizing PHP intermediate code. The APC based caching is good for my web site, but my cron jobs and php cli scripts fail to
fetch correct data due to caching. How do I disable APC module at the command line (php-cli) under Linux or Unix like operating systems for all my cron jobs?

The bug may be fixed by applying stable APC patches. APC code is actively maintained. So try updating to the latest stable version. If you are using php-cli, php5-cli or php binary file directly from your scripts try passing -d option. This option can define and override INI entry that enables APC. The exact entry can be located using the following grep command line syntax:

### note php.ini path may be differnt under Unix or linux ###
grep --color -i enabled /etc/php.d/php.ini

Sample outputs:


Use the following syntax to define an entry apc.enabled with value 0 (disable it):

/usr/bin/php -d apc.enabled=0 my.cron.php
/usr/bin/php -d apc.enabled=0 /path/to/myshelljob.php
/usr/bin/php-cli -d apc.enabled=0 /path/to/myshelljob.php

Or you can create a small shell script wrapper for your cron jobs under Linux or Unix like oses:

# Purpose - Create search index file for AWS search web service for our db
# Author: nixCraft <www.cyberciti.biz> 
# ------------------------------------------------------------------------
_phpargs="-d apc.enabled=0"
[[ ! -d "$_tmp/$i" ]] && /bin/mkdir "$_tmp/$i"
## Run php with APC disabled ###
$_nice -n 3 $_php $_phpargs -f $_base/php/createsearchindex.php
Share this tutorial on:

Like this? Follow us on Twitter OR support us by using Patreon

{ 0 comments… add one }
Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , , ,