From ffc118767e4f8b4a56b6af89b307c1db5dc44e6b Mon Sep 17 00:00:00 2001 From: Nigel Chan Date: Mon, 6 Oct 2014 17:36:02 -0700 Subject: [PATCH] Convert APC to HNI Summary: fixes #3627 Reviewed By: @ptarjan Differential Revision: D1531906 --- hphp/runtime/base/apc-array.cpp | 2 +- hphp/runtime/base/apc-file-storage.cpp | 2 +- hphp/runtime/base/apc-handle.cpp | 2 +- hphp/runtime/base/apc-object.cpp | 2 +- hphp/runtime/base/apc-stats.cpp | 2 +- hphp/runtime/base/apc-typed-value.cpp | 2 +- hphp/runtime/base/concurrent-shared-store.cpp | 2 +- hphp/runtime/base/program-functions.cpp | 2 +- hphp/runtime/ext/{ => apc}/ext_apc.cpp | 129 +++++-- hphp/runtime/ext/{ => apc}/ext_apc.h | 54 ++- hphp/runtime/ext/apc/ext_apc.php | 202 +++++++++++ hphp/runtime/ext/ext.h | 1 - hphp/runtime/ext/extension.cpp | 1 + hphp/runtime/ext/soap/xml.cpp | 6 +- hphp/runtime/server/admin-request-handler.cpp | 2 +- hphp/runtime/server/upload.cpp | 2 +- hphp/runtime/vm/bytecode.cpp | 4 +- hphp/system/idl/apc.idl.json | 376 --------------------- hphp/test/ext/test_cpp_base.cpp | 4 +- hphp/test/ext/test_ext_apc.cpp | 2 +- .../slow/apc/apc_store_as_primed_do_not_use.php | 4 + .../apc/apc_store_as_primed_do_not_use.php.expect | 2 + hphp/test/slow/apc/constants.php | 21 ++ hphp/test/slow/apc/constants.php.expect | 19 ++ 24 files changed, 407 insertions(+), 438 deletions(-) rename hphp/runtime/ext/{ => apc}/ext_apc.cpp (91%) rename hphp/runtime/ext/{ => apc}/ext_apc.h (77%) create mode 100644 hphp/runtime/ext/apc/ext_apc.php delete mode 100644 hphp/system/idl/apc.idl.json create mode 100644 hphp/test/slow/apc/apc_store_as_primed_do_not_use.php create mode 100644 hphp/test/slow/apc/apc_store_as_primed_do_not_use.php.expect create mode 100644 hphp/test/slow/apc/constants.php create mode 100644 hphp/test/slow/apc/constants.php.expect diff --git a/hphp/runtime/base/apc-array.cpp b/hphp/runtime/base/apc-array.cpp index ba5e2ed50f6..676c34f5330 100644 --- a/hphp/runtime/base/apc-array.cpp +++ b/hphp/runtime/base/apc-array.cpp @@ -26,7 +26,7 @@ #include "hphp/runtime/base/apc-local-array-defs.h" #include "hphp/runtime/base/array-iterator.h" #include "hphp/runtime/base/mixed-array-defs.h" -#include "hphp/runtime/ext/ext_apc.h" +#include "hphp/runtime/ext/apc/ext_apc.h" namespace HPHP { diff --git a/hphp/runtime/base/apc-file-storage.cpp b/hphp/runtime/base/apc-file-storage.cpp index 5faeaaa2e6d..4ef131c2c98 100644 --- a/hphp/runtime/base/apc-file-storage.cpp +++ b/hphp/runtime/base/apc-file-storage.cpp @@ -27,7 +27,7 @@ #include "hphp/runtime/base/builtin-functions.h" #include "hphp/runtime/server/server-stats.h" #include "hphp/runtime/base/apc-stats.h" -#include "hphp/runtime/ext/ext_apc.h" +#include "hphp/runtime/ext/apc/ext_apc.h" #if !defined(HAVE_POSIX_FALLOCATE) && \ (_XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L || defined(__CYGWIN__)) diff --git a/hphp/runtime/base/apc-handle.cpp b/hphp/runtime/base/apc-handle.cpp index 6b2fea88e66..eea0cc56df4 100644 --- a/hphp/runtime/base/apc-handle.cpp +++ b/hphp/runtime/base/apc-handle.cpp @@ -20,7 +20,7 @@ #include "hphp/runtime/base/apc-array.h" #include "hphp/runtime/base/apc-object.h" #include "hphp/runtime/base/mixed-array.h" -#include "hphp/runtime/ext/ext_apc.h" +#include "hphp/runtime/ext/apc/ext_apc.h" namespace HPHP { diff --git a/hphp/runtime/base/apc-object.cpp b/hphp/runtime/base/apc-object.cpp index bbb0b1bd9e3..edd3a4ca56f 100644 --- a/hphp/runtime/base/apc-object.cpp +++ b/hphp/runtime/base/apc-object.cpp @@ -29,7 +29,7 @@ #include "hphp/runtime/base/array-iterator.h" #include "hphp/runtime/base/class-info.h" #include "hphp/runtime/base/builtin-functions.h" -#include "hphp/runtime/ext/ext_apc.h" +#include "hphp/runtime/ext/apc/ext_apc.h" namespace HPHP { diff --git a/hphp/runtime/base/apc-stats.cpp b/hphp/runtime/base/apc-stats.cpp index 98c463ff10b..5e7fd4ee096 100644 --- a/hphp/runtime/base/apc-stats.cpp +++ b/hphp/runtime/base/apc-stats.cpp @@ -23,7 +23,7 @@ #include "hphp/runtime/base/apc-handle.h" #include "hphp/runtime/base/apc-array.h" #include "hphp/runtime/base/apc-object.h" -#include "hphp/runtime/ext/ext_apc.h" +#include "hphp/runtime/ext/apc/ext_apc.h" namespace HPHP { /////////////////////////////////////////////////////////////////////////////// diff --git a/hphp/runtime/base/apc-typed-value.cpp b/hphp/runtime/base/apc-typed-value.cpp index 44b0a44a97a..8f1c6b06034 100644 --- a/hphp/runtime/base/apc-typed-value.cpp +++ b/hphp/runtime/base/apc-typed-value.cpp @@ -16,7 +16,7 @@ #include "hphp/runtime/base/apc-typed-value.h" #include "hphp/runtime/base/mixed-array.h" -#include "hphp/runtime/ext/ext_apc.h" +#include "hphp/runtime/ext/apc/ext_apc.h" namespace HPHP { diff --git a/hphp/runtime/base/concurrent-shared-store.cpp b/hphp/runtime/base/concurrent-shared-store.cpp index 9bef35a2095..27b50f6a431 100644 --- a/hphp/runtime/base/concurrent-shared-store.cpp +++ b/hphp/runtime/base/concurrent-shared-store.cpp @@ -28,7 +28,7 @@ #include "hphp/runtime/base/apc-object.h" #include "hphp/runtime/base/apc-stats.h" #include "hphp/runtime/base/apc-file-storage.h" -#include "hphp/runtime/ext/ext_apc.h" +#include "hphp/runtime/ext/apc/ext_apc.h" #include "hphp/runtime/vm/treadmill.h" namespace HPHP { diff --git a/hphp/runtime/base/program-functions.cpp b/hphp/runtime/base/program-functions.cpp index 70607d6cbb2..8d02f36c54c 100644 --- a/hphp/runtime/base/program-functions.cpp +++ b/hphp/runtime/base/program-functions.cpp @@ -39,11 +39,11 @@ #include "hphp/runtime/debugger/debugger.h" #include "hphp/runtime/debugger/debugger_client.h" #include "hphp/runtime/debugger/debugger_hook_handler.h" -#include "hphp/runtime/ext/ext_apc.h" #include "hphp/runtime/ext/ext_fb.h" #include "hphp/runtime/ext/ext_file.h" #include "hphp/runtime/ext/ext_function.h" #include "hphp/runtime/ext/extension.h" +#include "hphp/runtime/ext/apc/ext_apc.h" #include "hphp/runtime/ext/json/ext_json.h" #include "hphp/runtime/ext/std/ext_std_options.h" #include "hphp/runtime/ext/std/ext_std_variable.h" diff --git a/hphp/runtime/ext/ext_apc.cpp b/hphp/runtime/ext/apc/ext_apc.cpp similarity index 91% rename from hphp/runtime/ext/ext_apc.cpp rename to hphp/runtime/ext/apc/ext_apc.cpp index 909f38d5c72..bb58798f39e 100644 --- a/hphp/runtime/ext/ext_apc.cpp +++ b/hphp/runtime/ext/apc/ext_apc.cpp @@ -14,7 +14,7 @@ | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ */ -#include "hphp/runtime/ext/ext_apc.h" +#include "hphp/runtime/ext/apc/ext_apc.h" #include @@ -72,6 +72,33 @@ void initialize_apc() { ////////////////////////////////////////////////////////////////////// +#define DEFINE_CONSTANT(name, value) \ + static const int64_t k_##name = value; \ + static const StaticString s_##name(#name) \ + +#define REGISTER_CONSTANT(name) \ + Native::registerConstant(s_##name.get(), k_##name) \ + +DEFINE_CONSTANT(APC_ITER_TYPE, 0x1); +DEFINE_CONSTANT(APC_ITER_KEY, 0x2); +DEFINE_CONSTANT(APC_ITER_FILENAME, 0x4); +DEFINE_CONSTANT(APC_ITER_DEVICE, 0x8); +DEFINE_CONSTANT(APC_ITER_INODE, 0x10); +DEFINE_CONSTANT(APC_ITER_VALUE, 0x20); +DEFINE_CONSTANT(APC_ITER_MD5, 0x40); +DEFINE_CONSTANT(APC_ITER_NUM_HITS, 0x80); +DEFINE_CONSTANT(APC_ITER_MTIME, 0x100); +DEFINE_CONSTANT(APC_ITER_CTIME, 0x200); +DEFINE_CONSTANT(APC_ITER_DTIME, 0x400); +DEFINE_CONSTANT(APC_ITER_ATIME, 0x800); +DEFINE_CONSTANT(APC_ITER_REFCOUNT, 0x1000); +DEFINE_CONSTANT(APC_ITER_MEM_SIZE, 0x2000); +DEFINE_CONSTANT(APC_ITER_TTL, 0x4000); +DEFINE_CONSTANT(APC_ITER_NONE, 0x0); +DEFINE_CONSTANT(APC_ITER_ALL, 0xFFFFFFFFFF); +DEFINE_CONSTANT(APC_LIST_ACTIVE, 1); +DEFINE_CONSTANT(APC_LIST_DELETED, 2); + const StaticString s_delete("delete"); @@ -136,6 +163,40 @@ void apcExtension::moduleInit() { FileStorageChunkSize, FileStorageMaxSize); } + + REGISTER_CONSTANT(APC_ITER_TYPE); + REGISTER_CONSTANT(APC_ITER_KEY); + REGISTER_CONSTANT(APC_ITER_FILENAME); + REGISTER_CONSTANT(APC_ITER_DEVICE); + REGISTER_CONSTANT(APC_ITER_INODE); + REGISTER_CONSTANT(APC_ITER_VALUE); + REGISTER_CONSTANT(APC_ITER_MD5); + REGISTER_CONSTANT(APC_ITER_NUM_HITS); + REGISTER_CONSTANT(APC_ITER_MTIME); + REGISTER_CONSTANT(APC_ITER_CTIME); + REGISTER_CONSTANT(APC_ITER_DTIME); + REGISTER_CONSTANT(APC_ITER_ATIME); + REGISTER_CONSTANT(APC_ITER_REFCOUNT); + REGISTER_CONSTANT(APC_ITER_MEM_SIZE); + REGISTER_CONSTANT(APC_ITER_TTL); + REGISTER_CONSTANT(APC_ITER_NONE); + REGISTER_CONSTANT(APC_ITER_ALL); + REGISTER_CONSTANT(APC_LIST_ACTIVE); + REGISTER_CONSTANT(APC_LIST_DELETED); + + HHVM_FE(apc_add); + HHVM_FE(apc_store); + HHVM_FE(apc_store_as_primed_do_not_use); + HHVM_FE(apc_fetch); + HHVM_FE(apc_delete); + HHVM_FE(apc_clear_cache); + HHVM_FE(apc_inc); + HHVM_FE(apc_dec); + HHVM_FE(apc_cas); + HHVM_FE(apc_exists); + HHVM_FE(apc_cache_info); + HHVM_FE(apc_sma_info); + loadSystemlib(); } void apcExtension::moduleShutdown() { @@ -177,10 +238,10 @@ bool apcExtension::EnableCLI = true; static apcExtension s_apc_extension; -/////////////////////////////////////////////////////////////////////////////// -Variant f_apc_store(const Variant& key_or_array, - const Variant& var /* = null_variant */, - int64_t ttl /* = 0 */) { +Variant HHVM_FUNCTION(apc_store, + const Variant& key_or_array, + const Variant& var /* = null */, + int64_t ttl /* = 0 */) { if (!apcExtension::Enable) return Variant(false); if (key_or_array.is(KindOfArray)) { @@ -212,15 +273,18 @@ Variant f_apc_store(const Variant& key_or_array, * Stores the key in a similar fashion as "priming" would do (no TTL limit). * Using this function is equivalent to adding your key to apc_prime.so. */ -bool f_apc_store_as_primed_do_not_use(const String& key, const Variant& var) { +bool HHVM_FUNCTION(apc_store_as_primed_do_not_use, + const String& key, + const Variant& var) { if (!apcExtension::Enable) return false; apc_store().setWithoutTTL(key, var); return true; } -Variant f_apc_add(const Variant& key_or_array, - const Variant& var /* = null_variant */, - int64_t ttl /* = 0 */) { +Variant HHVM_FUNCTION(apc_add, + const Variant& key_or_array, + const Variant& var /* = null */, + int64_t ttl /* = 0 */) { if (!apcExtension::Enable) return false; if (key_or_array.is(KindOfArray)) { @@ -251,7 +315,9 @@ Variant f_apc_add(const Variant& key_or_array, return apc_store().add(strKey, var, ttl); } -Variant f_apc_fetch(const Variant& key, VRefParam success /* = null */) { +Variant HHVM_FUNCTION(apc_fetch, + const Variant& key, + VRefParam success /* = null */) { if (!apcExtension::Enable) return false; Variant v; @@ -285,7 +351,8 @@ Variant f_apc_fetch(const Variant& key, VRefParam success /* = null */) { return v; } -Variant f_apc_delete(const Variant& key) { +Variant HHVM_FUNCTION(apc_delete, + const Variant& key) { if (!apcExtension::Enable) return false; if (key.is(KindOfArray)) { @@ -321,13 +388,16 @@ Variant f_apc_delete(const Variant& key) { return apc_store().erase(key.toString()); } -bool f_apc_clear_cache(const String& cache_type /* = "" */) { +bool HHVM_FUNCTION(apc_clear_cache, + const String& cache_type /* = "" */) { if (!apcExtension::Enable) return false; return apc_store().clear(); } -Variant f_apc_inc(const String& key, int64_t step /* = 1 */, - VRefParam success /* = null */) { +Variant HHVM_FUNCTION(apc_inc, + const String& key, + int64_t step /* = 1 */, + VRefParam success /* = null */) { if (!apcExtension::Enable) return false; bool found = false; @@ -337,8 +407,10 @@ Variant f_apc_inc(const String& key, int64_t step /* = 1 */, return newValue; } -Variant f_apc_dec(const String& key, int64_t step /* = 1 */, - VRefParam success /* = null */) { +Variant HHVM_FUNCTION(apc_dec, + const String& key, + int64_t step /* = 1 */, + VRefParam success /* = null */) { if (!apcExtension::Enable) return false; bool found = false; @@ -348,12 +420,16 @@ Variant f_apc_dec(const String& key, int64_t step /* = 1 */, return newValue; } -bool f_apc_cas(const String& key, int64_t old_cas, int64_t new_cas) { +bool HHVM_FUNCTION(apc_cas, + const String& key, + int64_t old_cas, + int64_t new_cas) { if (!apcExtension::Enable) return false; return apc_store().cas(key, old_cas, new_cas); } -Variant f_apc_exists(const Variant& key) { +Variant HHVM_FUNCTION(apc_exists, + const Variant& key) { if (!apcExtension::Enable) return false; if (key.is(KindOfArray)) { @@ -394,8 +470,9 @@ const uint32_t kCacheInfoSize = 40; // Number of elements in the entry array const int32_t kEntryInfoSize = 5; -Variant f_apc_cache_info(const String& cache_type, - bool limited /* = false */) { +Variant HHVM_FUNCTION(apc_cache_info, + const String& cache_type, + bool limited /* = false */) { ArrayInit info(kCacheInfoSize, ArrayInit::Map{}); info.add(s_start_time, start_time()); if (cache_type.size() != 0 && !cache_type.same(s_user)) { @@ -426,7 +503,8 @@ Variant f_apc_cache_info(const String& cache_type, return info.toArray(); } -Array f_apc_sma_info(bool limited /* = false */) { +Array HHVM_FUNCTION(apc_sma_info, + bool limited /* = false */) { return empty_array(); } @@ -1207,7 +1285,7 @@ int apc_rfc1867_progress(apc_rfc1867_data *rfc1867ApcData, track.set(s_name, rfc1867ApcData->name); track.set(s_done, 0); track.set(s_start_time, rfc1867ApcData->start_time); - f_apc_store(rfc1867ApcData->tracking_key, track.create(), 3600); + HHVM_FN(apc_store)(rfc1867ApcData->tracking_key, track.create(), 3600); } break; @@ -1229,7 +1307,8 @@ int apc_rfc1867_progress(apc_rfc1867_data *rfc1867ApcData, track.set(s_name, rfc1867ApcData->name); track.set(s_done, 0); track.set(s_start_time, rfc1867ApcData->start_time); - f_apc_store(rfc1867ApcData->tracking_key, track.create(), 3600); + HHVM_FN(apc_store)(rfc1867ApcData->tracking_key, track.create(), + 3600); } rfc1867ApcData->prev_bytes_processed = rfc1867ApcData->bytes_processed; @@ -1254,7 +1333,7 @@ int apc_rfc1867_progress(apc_rfc1867_data *rfc1867ApcData, track.set(s_cancel_upload, rfc1867ApcData->cancel_upload); track.set(s_done, 0); track.set(s_start_time, rfc1867ApcData->start_time); - f_apc_store(rfc1867ApcData->tracking_key, track.create(), 3600); + HHVM_FN(apc_store)(rfc1867ApcData->tracking_key, track.create(), 3600); } break; @@ -1278,7 +1357,7 @@ int apc_rfc1867_progress(apc_rfc1867_data *rfc1867ApcData, track.set(s_cancel_upload, rfc1867ApcData->cancel_upload); track.set(s_done, 1); track.set(s_start_time, rfc1867ApcData->start_time); - f_apc_store(rfc1867ApcData->tracking_key, track.create(), 3600); + HHVM_FN(apc_store)(rfc1867ApcData->tracking_key, track.create(), 3600); } } break; diff --git a/hphp/runtime/ext/ext_apc.h b/hphp/runtime/ext/apc/ext_apc.h similarity index 77% rename from hphp/runtime/ext/ext_apc.h rename to hphp/runtime/ext/apc/ext_apc.h index de238865bbf..5ecacb8bd9b 100644 --- a/hphp/runtime/ext/ext_apc.h +++ b/hphp/runtime/ext/apc/ext_apc.h @@ -68,26 +68,46 @@ class apcExtension : public Extension { }; /////////////////////////////////////////////////////////////////////////////// -Variant f_apc_add(const Variant& key_or_array, const Variant& var = null_variant, - int64_t ttl = 0); -Variant f_apc_store(const Variant& key_or_array, const Variant& var = null_variant, - int64_t ttl = 0); -bool f_apc_store_as_primed_do_not_use(const String& key, const Variant& var); - -Variant f_apc_fetch(const Variant& key, VRefParam success = uninit_null()); -Variant f_apc_delete(const Variant& key); -bool f_apc_clear_cache(const String& cache_type = ""); -Variant f_apc_inc(const String& key, int64_t step = 1, - VRefParam success = uninit_null()); -Variant f_apc_dec(const String& key, int64_t step = 1, - VRefParam success = uninit_null()); -bool f_apc_cas(const String& key, int64_t old_cas, int64_t new_cas); -Variant f_apc_exists(const String& cache_type); +Variant HHVM_FUNCTION(apc_add, + const Variant& key_or_array, + const Variant& var = null_variant, + int64_t ttl = 0); +Variant HHVM_FUNCTION(apc_store, + const Variant& key_or_array, + const Variant& var = null_variant, + int64_t ttl = 0); +bool HHVM_FUNCTION(apc_store_as_primed_do_not_use, + const String& key, + const Variant& var); +Variant HHVM_FUNCTION(apc_fetch, + const Variant& key, + VRefParam success = uninit_null()); +Variant HHVM_FUNCTION(apc_delete, + const Variant& key); +bool HHVM_FUNCTION(apc_clear_cache, + const String& cache_type = ""); +Variant HHVM_FUNCTION(apc_inc, + const String& key, + int64_t step = 1, + VRefParam success = uninit_null()); +Variant HHVM_FUNCTION(apc_dec, + const String& key, + int64_t step = 1, + VRefParam success = uninit_null()); +bool HHVM_FUNCTION(apc_cas, + const String& key, + int64_t old_cas, + int64_t new_cas); +Variant HHVM_FUNCTION(apc_exists, + const Variant& key); /////////////////////////////////////////////////////////////////////////////// -Variant f_apc_cache_info(const String& cache_type = "", bool limited = false); -Array f_apc_sma_info(bool limited = false); +Variant HHVM_FUNCTION(apc_cache_info, + const String& cache_type /* = "" */, + bool limited /* = false */); +Array HHVM_FUNCTION(apc_sma_info, + bool limited /* = false */); /////////////////////////////////////////////////////////////////////////////// // loading APC from archive files diff --git a/hphp/runtime/ext/apc/ext_apc.php b/hphp/runtime/ext/apc/ext_apc.php new file mode 100644 index 00000000000..efad1cf6b87 --- /dev/null +++ b/hphp/runtime/ext/apc/ext_apc.php @@ -0,0 +1,202 @@ +> +function apc_add(mixed $key_or_array, + mixed $var = null, + int $ttl = 0): mixed; + +/** + * Cache a variable in the data store. Unlike many other mechanisms in PHP, + * variables stored using apc_store() will persist between requests (until the + * value is removed from the cache). + * + * @param mixed $key_or_array - Store the variable using this name. Can also + * be an array of key-value pairs to insert into the cache. Keys are + * cache-unique, so storing a second value with the same key will overwrite + * the original value. + * @param mixed $var - The variable to store. Defaults to null for the case + * where an array of key-value pairs is passed. + * @param int $ttl - Time To Live; store var in the cache for ttl seconds. + * After the ttl has passed, the stored variable will be expunged from the + * cache (on the next request). If no ttl is supplied (or if the ttl is 0), + * the value will persist until it is removed from the cache manually, or + * otherwise fails to exist in the cache (clear, restart, etc.). + * + * @return mixed - Returns TRUE on success, FALSE on failure and an array with + * error keys if passed an array. + * + */ +<<__Native>> +function apc_store(mixed $key_or_array, + mixed $var = null, + int $ttl = 0): mixed; + +/** + * Simlar to apc_store() but TTL is always 0 and there is TTL cap applied. Do + * not use in prod, use cachearchiver instead. + * + * @param string $key - Store the variable using this name. keys are + * cache-unique, so storing a second value with the same key will overwrite + * the original value. + * @param mixed $var - The variable to store + * + * @return bool - Returns TRUE on success or FALSE on failure. + * + */ +<<__Native>> +function apc_store_as_primed_do_not_use(string $key, + mixed $var): bool; + +/** + * Fetchs a stored variable from the cache. + * + * @param mixed $key - The key used to store the value (with apc_store()). If + * an array is passed then each element is fetched and returned. + * @param mixed $success - Set to TRUE in success and FALSE in failure. + * + * @return mixed - The stored variable or array of variables on success; FALSE + * on failure + * + */ +<<__Native>> +function apc_fetch(mixed $key, + mixed &$success = null): mixed; + +/** + * Removes a stored variable from the cache. + * + * @param mixed $key - The key used to store the value (with apc_store()). + * + * @return mixed - Returns TRUE on success or FALSE on failure. + * + */ +<<__Native>> +function apc_delete(mixed $key): mixed; + +/** + * Retrieves cached information and meta-data from APC's data store. + * + * @param string $cache_type - If cache_type is "user", information about the + * user cache will be returned. If cache_type is "filehits", information + * about which files have been served from the bytecode cache for the current + * request will be returned. This feature must be enabled at compile time + * using --enable-filehits . If an invalid or no cache_type is specified, + * information about the system cache (cached files) will be returned. + * @param bool $limited - If limited is TRUE, the return value will exclude + * the individual list of cache entries. This is useful when trying to + * optimize calls for statistics gathering. + * + * @return mixed - Array of cached data (and meta-data) or FALSE on failure + * apc_cache_info() will raise a warning if it is unable to retrieve APC cache + * data. This typically occurs when APC is not enabled. + * + */ +<<__Native>> +function apc_cache_info(string $cache_type = "", bool $limited = false): mixed; + +/** + * Clears the user/system cache. + * + * @return bool - Returns TRUE on success or FALSE on failure. + * + */ +<<__Native>> +function apc_clear_cache(string $cache_type = ""): bool; + +/** + * Retrieves APC's Shared Memory Allocation information. + * + * @param bool $limited - When set to FALSE (default) apc_sma_info() will + * return a detailed information about each segment. + * + * @return array - Array of Shared Memory Allocation data; FALSE on failure. + * + */ +<<__Native>> +function apc_sma_info(bool $limited = false): array; + +/** + * Increases a stored number. + * + * @param string $key - The key of the value being increased. + * @param int $step - The step, or value to increase. + * @param mixed $success - Optionally pass the success or fail boolean value + * to this referenced variable. + * + * @return mixed - Returns the current value of key's value on success, or + * FALSE on failure + * + */ +<<__Native>> +function apc_inc(string $key, + int $step = 1, + mixed &$success = null): mixed; + +/** + * Decreases a stored integer value. + * + * @param string $key - The key of the value being decreased. + * @param int $step - The step, or value to decrease. + * @param mixed $success - Optionally pass the success or fail boolean value + * to this referenced variable. + * + * @return mixed - Returns the current value of key's value on success, or + * FALSE on failure + * + */ +<<__Native>> +function apc_dec(string $key, + int $step = 1, + mixed &$success = null): mixed; + +/** + * Update an existing old value to a new value. + * + * @param string $key - The key of the value being updated. + * @param int $old_cas - The old value that is currently stored. + * @param int $new_cas - The new value to update to. + * + * @return bool - Returns TRUE on success or FALSE on failure. + * + */ +<<__Native>> +function apc_cas(string $key, + int $old_cas, + int $new_cas): bool; + +/** + * Checks if one ore more APC keys exist. + * + * @param mixed $key - The key to check existence. If an array is passed then + * each element is checked. + * + * @return mixed - TRUE if the key exists, otherwise FALSE. If array is passed + * in, then an array is returned that contains all existing keys, or an empty + * array if none exist. + * + */ +<<__Native>> +function apc_exists(mixed $key): mixed; diff --git a/hphp/runtime/ext/ext.h b/hphp/runtime/ext/ext.h index 1f313f0e5cc..c52465f5778 100644 --- a/hphp/runtime/ext/ext.h +++ b/hphp/runtime/ext/ext.h @@ -30,7 +30,6 @@ #include "hphp/facebook/extensions/string_buffer/ext_string_buffer.h" #endif -#include "hphp/runtime/ext/ext_apc.h" #include "hphp/runtime/ext/array/ext_array_idl.h" #include "hphp/runtime/ext/ext_closure.h" #include "hphp/runtime/ext/ext_collections.h" diff --git a/hphp/runtime/ext/extension.cpp b/hphp/runtime/ext/extension.cpp index 7013050eef7..ca0b627b6e4 100644 --- a/hphp/runtime/ext/extension.cpp +++ b/hphp/runtime/ext/extension.cpp @@ -21,6 +21,7 @@ #include "hphp/util/exception.h" #include "hphp/util/assertions.h" #include "hphp/runtime/ext/apache/ext_apache.h" +#include "hphp/runtime/ext/apc/ext_apc.h" #include "hphp/runtime/ext/string/ext_string.h" #include "hphp/runtime/base/complex-types.h" #include "hphp/runtime/base/program-functions.h" diff --git a/hphp/runtime/ext/soap/xml.cpp b/hphp/runtime/ext/soap/xml.cpp index 949c27b6f4a..53bf1f38d58 100644 --- a/hphp/runtime/ext/soap/xml.cpp +++ b/hphp/runtime/ext/soap/xml.cpp @@ -18,7 +18,7 @@ #include "hphp/runtime/ext/soap/xml.h" #include "hphp/runtime/ext/ext_file.h" #include "hphp/runtime/ext/stream/ext_stream.h" -#include "hphp/runtime/ext/ext_apc.h" +#include "hphp/runtime/ext/apc/ext_apc.h" namespace HPHP { /////////////////////////////////////////////////////////////////////////////// @@ -77,14 +77,14 @@ xmlDocPtr soap_xmlParseFile(const char *filename) { String cache_key("HPHP.SOAP.WSDL."); cache_key += filename; - Variant content = f_apc_fetch(cache_key); + Variant content = HHVM_FN(apc_fetch)(cache_key); if (same(content, false)) { Resource resource = File::Open(filename, "rb", 0, f_stream_context_create( make_map_array(s_http, make_map_array(s_timeout, 1000)))); if (!resource.isNull()) { content = f_stream_get_contents(resource); if (!same(content, false)) { - f_apc_store(cache_key, content); + HHVM_FN(apc_store)(cache_key, content); } } } diff --git a/hphp/runtime/server/admin-request-handler.cpp b/hphp/runtime/server/admin-request-handler.cpp index 906b225b6be..52057332ee4 100644 --- a/hphp/runtime/server/admin-request-handler.cpp +++ b/hphp/runtime/server/admin-request-handler.cpp @@ -53,8 +53,8 @@ #include "hphp/util/alloc.h" #include "hphp/util/timer.h" #include "hphp/util/repo-schema.h" +#include "hphp/runtime/ext/apc/ext_apc.h" #include "hphp/runtime/ext/ext_fb.h" -#include "hphp/runtime/ext/ext_apc.h" #include "hphp/util/stacktrace-profiler.h" namespace HPHP { diff --git a/hphp/runtime/server/upload.cpp b/hphp/runtime/server/upload.cpp index 47949ee8211..07b5cb30898 100644 --- a/hphp/runtime/server/upload.cpp +++ b/hphp/runtime/server/upload.cpp @@ -22,7 +22,7 @@ #include "hphp/runtime/base/request-local.h" #include "hphp/runtime/base/zend-printf.h" #include "hphp/runtime/base/php-globals.h" -#include "hphp/runtime/ext/ext_apc.h" +#include "hphp/runtime/ext/apc/ext_apc.h" #include "hphp/util/logger.h" #include "hphp/runtime/base/string-util.h" #include "hphp/util/text-util.h" diff --git a/hphp/runtime/vm/bytecode.cpp b/hphp/runtime/vm/bytecode.cpp index 20aeb436cea..1a383f8137a 100644 --- a/hphp/runtime/vm/bytecode.cpp +++ b/hphp/runtime/vm/bytecode.cpp @@ -77,8 +77,7 @@ #include "hphp/runtime/ext/ext_closure.h" #include "hphp/runtime/ext/ext_generator.h" #include "hphp/runtime/ext/ext_function.h" -#include "hphp/runtime/ext/std/ext_std_variable.h" -#include "hphp/runtime/ext/ext_apc.h" +#include "hphp/runtime/ext/apc/ext_apc.h" #include "hphp/runtime/ext/array/ext_array.h" #include "hphp/runtime/ext/asio/async_function_wait_handle.h" #include "hphp/runtime/ext/asio/async_generator.h" @@ -87,6 +86,7 @@ #include "hphp/runtime/ext/asio/wait_handle.h" #include "hphp/runtime/ext/asio/waitable_wait_handle.h" #include "hphp/runtime/ext/reflection/ext_reflection.h" +#include "hphp/runtime/ext/std/ext_std_variable.h" #include "hphp/runtime/ext/string/ext_string.h" #include "hphp/runtime/base/stats.h" #include "hphp/runtime/vm/type-profile.h" diff --git a/hphp/system/idl/apc.idl.json b/hphp/system/idl/apc.idl.json deleted file mode 100644 index 9b9dbd80437..00000000000 --- a/hphp/system/idl/apc.idl.json +++ /dev/null @@ -1,376 +0,0 @@ -{ - "preamble": "", - "consts": [ - { - "name": "APC_ITER_TYPE", - "value": 1 - }, - { - "name": "APC_ITER_KEY", - "value": 2 - }, - { - "name": "APC_ITER_FILENAME", - "value": 4 - }, - { - "name": "APC_ITER_DEVICE", - "value": 8 - }, - { - "name": "APC_ITER_INODE", - "value": 16 - }, - { - "name": "APC_ITER_VALUE", - "value": 32 - }, - { - "name": "APC_ITER_MD5", - "value": 64 - }, - { - "name": "APC_ITER_NUM_HITS", - "value": 128 - }, - { - "name": "APC_ITER_MTIME", - "value": 256 - }, - { - "name": "APC_ITER_CTIME", - "value": 512 - }, - { - "name": "APC_ITER_DTIME", - "value": 1024 - }, - { - "name": "APC_ITER_ATIME", - "value": 2048 - }, - { - "name": "APC_ITER_REFCOUNT", - "value": 4096 - }, - { - "name": "APC_ITER_MEM_SIZE", - "value": 8192 - }, - { - "name": "APC_ITER_TTL", - "value": 16384 - }, - { - "name": "APC_ITER_NONE", - "value": 0 - }, - { - "name": "APC_ITER_ALL", - "value": 1099511627775 - }, - { - "name": "APC_LIST_ACTIVE", - "value": 1 - }, - { - "name": "APC_LIST_DELETED", - "value": 2 - } - ], - "funcs": [ - { - "name": "apc_add", - "desc": "Caches a variable in the data store, only if it's not already stored. Unlike many other mechanisms in PHP, variables stored using apc_add() will persist between requests (until the value is removed from the cache).", - "flags": [ - "AllowIntercept" - ], - "return": { - "type": "Variant", - "desc": "Returns TRUE on success or FALSE on failure and an array with error keys if passed an array." - }, - "args": [ - { - "name": "key_or_array", - "type": "Variant", - "desc": "Store the variable using this name. Can also be an array of key-value pairs to insert into the cache. Keys are cache-unique, so attempting to use apc_add() to store data with a key that already exists will not overwrite the existing data, and will instead return FALSE. (This is the only difference between apc_add() and apc_store().)" - }, - { - "name": "var", - "type": "Variant", - "value": "null_variant", - "desc": "The variable to store. Defaults to null for the case where an array of key-value pairs is passed." - }, - { - "name": "ttl", - "type": "Int64", - "value": "0", - "desc": "Time To Live; store var in the cache for ttl seconds. After the ttl has passed, the stored variable will be expunged from the cache (on the next request). If no ttl is supplied (or if the ttl is 0), the value will persist until it is removed from the cache manually, or otherwise fails to exist in the cache (clear, restart, etc.)." - } - ] - }, - { - "name": "apc_store", - "desc": "Cache a variable in the data store. Unlike many other mechanisms in PHP, variables stored using apc_store() will persist between requests (until the value is removed from the cache).", - "flags": [ - "AllowIntercept" - ], - "return": { - "type": "Variant", - "desc": "Returns TRUE on success, FALSE on failure and an array with error keys if passed an array." - }, - "args": [ - { - "name": "key_or_array", - "type": "Variant", - "desc": "Store the variable using this name. Can also be an array of key-value pairs to insert into the cache. Keys are cache-unique, so storing a second value with the same key will overwrite the original value." - }, - { - "name": "var", - "type": "Variant", - "value": "null_variant", - "desc": "The variable to store. Defaults to null for the case where an array of key-value pairs is passed." - }, - { - "name": "ttl", - "type": "Int64", - "value": "0", - "desc": "Time To Live; store var in the cache for ttl seconds. After the ttl has passed, the stored variable will be expunged from the cache (on the next request). If no ttl is supplied (or if the ttl is 0), the value will persist until it is removed from the cache manually, or otherwise fails to exist in the cache (clear, restart, etc.)." - } - ] - }, - { - "name": "apc_store_as_primed_do_not_use", - "desc": "Simlar to apc_store() but TTL is always 0 and there is TTL cap applied. Do not use in prod, use cachearchiver instead.", - "flags": [ - "AllowIntercept" - ], - "return": { - "type": "Boolean", - "desc": "Returns TRUE on success or FALSE on failure." - }, - "args": [ - { - "name": "key", - "type": "String", - "desc": "Store the variable using this name. keys are cache-unique, so storing a second value with the same key will overwrite the original value." - }, - { - "name": "var", - "type": "Variant", - "desc": "The variable to store" - } - ] - }, - { - "name": "apc_fetch", - "desc": "Fetchs a stored variable from the cache.", - "flags": [ - "AllowIntercept" - ], - "return": { - "type": "Variant", - "desc": "The stored variable or array of variables on success; FALSE on failure" - }, - "args": [ - { - "name": "key", - "type": "Variant", - "desc": "The key used to store the value (with apc_store()). If an array is passed then each element is fetched and returned." - }, - { - "name": "success", - "type": "Variant", - "value": "null", - "desc": "Set to TRUE in success and FALSE in failure.", - "ref": true - } - ] - }, - { - "name": "apc_delete", - "desc": "Removes a stored variable from the cache.", - "flags": [ - "AllowIntercept" - ], - "return": { - "type": "Variant", - "desc": "Returns TRUE on success or FALSE on failure." - }, - "args": [ - { - "name": "key", - "type": "Variant", - "desc": "The key used to store the value (with apc_store())." - } - ] - }, - { - "name": "apc_cache_info", - "desc": "Retrieves cached information and meta-data from APC's data store.", - "flags": [ - ], - "return": { - "type": "Variant", - "desc": "Array of cached data (and meta-data) or FALSE on failure apc_cache_info() will raise a warning if it is unable to retrieve APC cache data. This typically occurs when APC is not enabled." - }, - "args": [ - { - "name": "cache_type", - "type": "String", - "value": "\"\"", - "desc": "If cache_type is \"user\", information about the user cache will be returned.\n\nIf cache_type is \"filehits\", information about which files have been served from the bytecode cache for the current request will be returned. This feature must be enabled at compile time using --enable-filehits .\n\nIf an invalid or no cache_type is specified, information about the system cache (cached files) will be returned." - }, - { - "name": "limited", - "type": "Boolean", - "value": "false", - "desc": "If limited is TRUE, the return value will exclude the individual list of cache entries. This is useful when trying to optimize calls for statistics gathering." - } - ] - }, - { - "name": "apc_clear_cache", - "desc": "Clears the user\/system cache.", - "flags": [ - ], - "return": { - "type": "Boolean", - "desc": "Returns TRUE on success or FALSE on failure." - }, - "args": [ - { - "name": "cache_type", - "type": "String", - "value": "\"\"", - "desc": "If cache_type is \"user\", the user cache will be cleared; otherwise, the system cache (cached files) will be cleared." - } - ] - }, - { - "name": "apc_sma_info", - "desc": "Retrieves APC's Shared Memory Allocation information.", - "flags": [ - ], - "return": { - "type": "VariantMap", - "desc": "Array of Shared Memory Allocation data; FALSE on failure." - }, - "args": [ - { - "name": "limited", - "type": "Boolean", - "value": "false", - "desc": "When set to FALSE (default) apc_sma_info() will return a detailed information about each segment." - } - ] - }, - { - "name": "apc_inc", - "desc": "Increases a stored number.", - "flags": [ - "AllowIntercept" - ], - "return": { - "type": "Variant", - "desc": "Returns the current value of key's value on success, or FALSE on failure" - }, - "args": [ - { - "name": "key", - "type": "String", - "desc": "The key of the value being increased." - }, - { - "name": "step", - "type": "Int64", - "value": "1", - "desc": "The step, or value to increase." - }, - { - "name": "success", - "type": "Variant", - "value": "null", - "desc": "Optionally pass the success or fail boolean value to this referenced variable.", - "ref": true - } - ] - }, - { - "name": "apc_dec", - "desc": "Decreases a stored integer value.", - "flags": [ - "AllowIntercept" - ], - "return": { - "type": "Variant", - "desc": "Returns the current value of key's value on success, or FALSE on failure" - }, - "args": [ - { - "name": "key", - "type": "String", - "desc": "The key of the value being decreased." - }, - { - "name": "step", - "type": "Int64", - "value": "1", - "desc": "The step, or value to decrease." - }, - { - "name": "success", - "type": "Variant", - "value": "null", - "desc": "Optionally pass the success or fail boolean value to this referenced variable.", - "ref": true - } - ] - }, - { - "name": "apc_cas", - "desc": "apc_cas WarningThis function is currently not documented; only its argument list is available.", - "flags": [ - "AllowIntercept" - ], - "return": { - "type": "Boolean", - "desc": "Returns TRUE on success or FALSE on failure." - }, - "args": [ - { - "name": "key", - "type": "String" - }, - { - "name": "old_cas", - "type": "Int64" - }, - { - "name": "new_cas", - "type": "Int64" - } - ] - }, - { - "name": "apc_exists", - "desc": "Checks if one ore more APC keys exist.", - "flags": [ - "AllowIntercept" - ], - "return": { - "type": "Variant", - "desc": "TRUE if the key exists, otherwise FALSE. If array is passed in, then an array is returned that contains all existing keys, or an empty array if none exist." - }, - "args": [ - { - "name": "key", - "type": "Variant", - "desc": "The key to check existence. If an array is passed then each element is checked." - } - ] - } - ], - "classes": [ - ] -} diff --git a/hphp/test/ext/test_cpp_base.cpp b/hphp/test/ext/test_cpp_base.cpp index f6868122628..b829126f524 100644 --- a/hphp/test/ext/test_cpp_base.cpp +++ b/hphp/test/ext/test_cpp_base.cpp @@ -19,10 +19,8 @@ #include "hphp/util/logger.h" #include "hphp/runtime/base/memory-manager.h" #include "hphp/runtime/base/builtin-functions.h" +#include "hphp/runtime/ext/apc/ext_apc.h" #include "hphp/runtime/ext/std/ext_std_variable.h" -#include "hphp/runtime/ext/string/ext_string.h" -#include "hphp/runtime/ext/ext_apc.h" -#include "hphp/runtime/base/apc-file-storage.h" #include "hphp/runtime/base/runtime-option.h" #include "hphp/runtime/server/ip-block-map.h" #include "hphp/system/systemlib.h" diff --git a/hphp/test/ext/test_ext_apc.cpp b/hphp/test/ext/test_ext_apc.cpp index f9090cba4dc..066fa213a65 100644 --- a/hphp/test/ext/test_ext_apc.cpp +++ b/hphp/test/ext/test_ext_apc.cpp @@ -15,7 +15,7 @@ */ #include "hphp/test/ext/test_ext_apc.h" -#include "hphp/runtime/ext/ext_apc.h" +#include "hphp/runtime/ext/apc/ext_apc.h" /////////////////////////////////////////////////////////////////////////////// diff --git a/hphp/test/slow/apc/apc_store_as_primed_do_not_use.php b/hphp/test/slow/apc/apc_store_as_primed_do_not_use.php new file mode 100644 index 00000000000..246f111297a --- /dev/null +++ b/hphp/test/slow/apc/apc_store_as_primed_do_not_use.php @@ -0,0 +1,4 @@ +