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

by on November 5, 2012 · 0 comments· LAST UPDATED November 6, 2012

in ,

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?

Tutorial details
DifficultyIntermediate (rss)
Root privilegesNo
RequirementsPHP / shell
Estimated completion timeN/A

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:

apc.enabled=1

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:

 
#!/bin/bash
# Purpose - Create search index file for AWS search web service for our db
# Author: nixCraft <www.cyberciti.biz> 
# ------------------------------------------------------------------------
_php="/usr/bin/php"
_nice="/bin/nice"
_phpargs="-d apc.enabled=0"
_base="/opt/sysadmin/aws"
_tmp="$_base/tmp"
[[ ! -d "$_tmp/$i" ]] && /bin/mkdir "$_tmp/$i"
 
## Run php with APC disabled ###
$_nice -n 3 $_php $_phpargs -f $_base/php/createsearchindex.php
 
TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 0 comments… add one now }

Leave a Comment

Tagged as: , , , ,

Previous Faq:

Next Faq: