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?

Tutorial details
DifficultyIntermediate (rss)
Root privilegesNo
RequirementsPHP / shell
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 <> 
# ------------------------------------------------------------------------
_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
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.