THRIFT-5130 Use Apcu instead of APC
Client: PHP
Patch: Vladimir Panivko

This closes #2041
diff --git a/lib/cpp/src/thrift/transport/TSocketPool.cpp b/lib/cpp/src/thrift/transport/TSocketPool.cpp
index b6e79d3..f56c76e 100644
--- a/lib/cpp/src/thrift/transport/TSocketPool.cpp
+++ b/lib/cpp/src/thrift/transport/TSocketPool.cpp
@@ -178,7 +178,7 @@
  * This function throws an exception if socket open fails. When socket
  * opens fails, the socket in the current server is reset.
  */
-/* TODO: without apc we ignore a lot of functionality from the php version */
+/* TODO: without apcu we ignore a lot of functionality from the php version */
 void TSocketPool::open() {
 
   size_t numServers = servers_.size();
diff --git a/lib/php/README.md b/lib/php/README.md
index 7170104..e7144fe 100644
--- a/lib/php/README.md
+++ b/lib/php/README.md
@@ -23,7 +23,7 @@
 
 Thrift requires PHP 5. Thrift makes as few assumptions about your PHP
 environment as possible while trying to make some more advanced PHP
-features (i.e. APC cacheing using asbolute path URLs) as simple as possible.
+features (i.e. APCu cacheing using asbolute path URLs) as simple as possible.
 
 To use Thrift in your PHP codebase, take the following steps:
 
@@ -46,9 +46,9 @@
     used by the TBinaryProtocol to properly use pack() and unpack() to
     serialize data.
 
-apc_fetch(), apc_store()
+apcu_fetch(), apcu_store()
 
-    APC cache is used by the TSocketPool class. If you do not have APC installed,
+    APCu cache is used by the TSocketPool class. If you do not have APCu installed,
     Thrift will fill in null stub function definitions.
 
 # Breaking Changes
diff --git a/lib/php/lib/ClassLoader/ThriftClassLoader.php b/lib/php/lib/ClassLoader/ThriftClassLoader.php
index 4361bd8..e4b4a17 100644
--- a/lib/php/lib/ClassLoader/ThriftClassLoader.php
+++ b/lib/php/lib/ClassLoader/ThriftClassLoader.php
@@ -40,26 +40,26 @@
     protected $definitions = array();
 
     /**
-     * Do we use APC cache ?
+     * Do we use APCu cache ?
      * @var boolean
      */
-    protected $apc = false;
+    protected $apcu = false;
 
     /**
-     * APC Cache prefix
+     * APCu Cache prefix
      * @var string
      */
-    protected $apc_prefix;
+    protected $apcu_prefix;
 
     /**
-     * Set autoloader to use APC cache
+     * Set autoloader to use APCu cache
      * @param boolean $apc
-     * @param string $apc_prefix
+     * @param string $apcu_prefix
      */
-    public function __construct($apc = false, $apc_prefix = null)
+    public function __construct($apc = false, $apcu_prefix = null)
     {
-        $this->apc = $apc;
-        $this->apc_prefix = $apc_prefix;
+        $this->apcu = $apc;
+        $this->apcu_prefix = $apcu_prefix;
     }
 
     /**
@@ -101,7 +101,7 @@
      */
     public function loadClass($class)
     {
-        if ((true === $this->apc && ($file = $this->findFileInApc($class))) or
+        if ((true === $this->apcu && ($file = $this->findFileInApcu($class))) or
             ($file = $this->findFile($class))
         ) {
             require_once $file;
@@ -109,14 +109,14 @@
     }
 
     /**
-     * Loads the given class or interface in APC.
+     * Loads the given class or interface in APCu.
      * @param  string $class The name of the class
      * @return string
      */
-    protected function findFileInApc($class)
+    protected function findFileInApcu($class)
     {
-        if (false === $file = apc_fetch($this->apc_prefix . $class)) {
-            apc_store($this->apc_prefix . $class, $file = $this->findFile($class));
+        if (false === $file = apcu_fetch($this->apcu_prefix . $class)) {
+            apcu_store($this->apcu_prefix . $class, $file = $this->findFile($class));
         }
 
         return $file;
diff --git a/lib/php/lib/Transport/TSocketPool.php b/lib/php/lib/Transport/TSocketPool.php
index cb9e8dd..307885f 100644
--- a/lib/php/lib/Transport/TSocketPool.php
+++ b/lib/php/lib/Transport/TSocketPool.php
@@ -25,18 +25,18 @@
 use Thrift\Exception\TException;
 
 /**
- * This library makes use of APC cache to make hosts as down in a web
- * environment. If you are running from the CLI or on a system without APC
+ * This library makes use of APCu cache to make hosts as down in a web
+ * environment. If you are running from the CLI or on a system without APCu
  * installed, then these null functions will step in and act like cache
  * misses.
  */
-if (!function_exists('apc_fetch')) {
-    function apc_fetch($key)
+if (!function_exists('apcu_fetch')) {
+    function apcu_fetch($key)
     {
         return false;
     }
 
-    function apc_store($key, $var, $ttl = 0)
+    function apcu_store($key, $var, $ttl = 0)
     {
         return false;
     }
@@ -202,11 +202,11 @@
             // This extracts the $host and $port variables
             extract($this->servers_[$i]);
 
-            // Check APC cache for a record of this server being down
+            // Check APCu cache for a record of this server being down
             $failtimeKey = 'thrift_failtime:' . $host . ':' . $port . '~';
 
             // Cache miss? Assume it's OK
-            $lastFailtime = apc_fetch($failtimeKey);
+            $lastFailtime = apcu_fetch($failtimeKey);
             if ($lastFailtime === false) {
                 $lastFailtime = 0;
             }
@@ -251,7 +251,7 @@
 
                         // Only clear the failure counts if required to do so
                         if ($lastFailtime > 0) {
-                            apc_store($failtimeKey, 0);
+                            apcu_store($failtimeKey, 0);
                         }
 
                         // Successful connection, return now
@@ -265,7 +265,7 @@
                 $consecfailsKey = 'thrift_consecfails:' . $host . ':' . $port . '~';
 
                 // Ignore cache misses
-                $consecfails = apc_fetch($consecfailsKey);
+                $consecfails = apcu_fetch($consecfailsKey);
                 if ($consecfails === false) {
                     $consecfails = 0;
                 }
@@ -284,12 +284,12 @@
                         );
                     }
                     // Store the failure time
-                    apc_store($failtimeKey, time());
+                    apcu_store($failtimeKey, time());
 
                     // Clear the count of consecutive failures
-                    apc_store($consecfailsKey, 0);
+                    apcu_store($consecfailsKey, 0);
                 } else {
-                    apc_store($consecfailsKey, $consecfails);
+                    apcu_store($consecfailsKey, $consecfails);
                 }
             }
         }