Commit a205e23e authored by Sebastian Kummer's avatar Sebastian Kummer

Merge pull request #633 in ZP/z-push from feature/ZP-1332-Add-IPC-wincache-provider to develop

* commit 'a6fc12ab':
  ZP-1332 Update vendor/ for new IpcWincacheProvider class.
  ZP-1332 Add IpcWincacheProvider.
parents a66c073c a6fc12ab
<?php
/***********************************************
* File : ipcwincache.php
* Project : Z-Push
* Descr : IPC Provider for PHP wincache extension
*
* Created : 04.12.2017
*
* Copyright 2017 messageconcept GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Consult LICENSE file for details
************************************************/
class IpcWincacheProvider implements IIpcProvider {
protected $type;
protected $allocate;
/**
* Constructor
*
* @param int $type
* @param int $allocate
* @param string $class
*/
public function __construct($type, $allocate, $class) {
if (!function_exists('wincache_lock')) {
throw new FatalMisconfigurationException("IpcWincacheProvider failure: PHP libraries for wincache not found. Please make sure the wincache extension is installed and enabled.");
}
$this->type = $type;
}
/**
* Reinitializes the IPC data by removing, detaching and re-allocating it.
*
* @access public
* @return boolean
*/
public function ReInitIPC() {
// We simply clear the whole wincache ucache
return wincache_ucache_clear();
}
/**
* Cleans up the IPC data block.
*
* @access public
* @return boolean
*/
public function Clean() {
return false;
}
/**
* Indicates if the IPC is active.
*
* @access public
* @return boolean
*/
public function IsActive() {
return true;
}
/**
* Blocks the class mutex.
* Method blocks until mutex is available!
* ATTENTION: make sure that you *always* release a blocked mutex!
*
* @access public
* @return boolean
*/
public function BlockMutex() {
if (!wincache_lock($this->type)) {
ZLog::Write(LOGLEVEL_INFO, sprintf("%s->BlockMutex(): could not acquire lock for '%s'", get_class($this), $this->type));
return false;
}
return true;
}
/**
* Releases the class mutex.
* After the release other processes are able to block the mutex themselves.
*
* @access public
* @return boolean
*/
public function ReleaseMutex() {
if (!wincache_unlock($this->type)) {
ZLog::Write(LOGLEVEL_INFO, sprintf("%s->ReleaseMutex(): could not release lock for '%s'", get_class($this), $this->type));
return false;
}
return true;
}
/**
* Indicates if the requested variable is available in IPC data.
*
* @param int $id int indicating the variable
*
* @access public
* @return boolean
*/
public function HasData($id = 2) {
$key = $this->type.':'.$id;
if (!wincache_ucache_exists($key)) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("%s->HasData(): no data found for key '%s'", get_class($this), $key));
return false;
}
return true;
}
/**
* Returns the requested variable from IPC data.
*
* @param int $id int indicating the variable
*
* @access public
* @return mixed
*/
public function GetData($id = 2) {
$key = $this->type.':'.$id;
$found = false;
$result = wincache_ucache_get($key, $found);
if (!$found) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("%s->GetData(): no data found for key '%s'", get_class($this), $key));
return;
}
return $result;
}
/**
* Writes the transmitted variable to IPC data.
* Subclasses may never use an id < 2!
*
* @param mixed $data data which should be saved into IPC data
* @param int $id int indicating the variable (bigger than 2!)
*
* @access public
* @return boolean
*/
public function SetData($data, $id = 2) {
$key = $this->type.':'.$id;
if (!wincache_ucache_set($key, $data)) {
ZLog::Write(LOGLEVEL_INFO, sprintf("%s->SetData(): failed to store data for key '%s': '%s'", get_class($this), $key, print_r($data, false)));
return false;
}
return true;
}
}
...@@ -33,6 +33,7 @@ abstract class InterProcessData { ...@@ -33,6 +33,7 @@ abstract class InterProcessData {
static private $providerLoadOrder = array( static private $providerLoadOrder = array(
'IpcSharedMemoryProvider' => 'backend/ipcsharedmemory/ipcsharedmemoryprovider.php', 'IpcSharedMemoryProvider' => 'backend/ipcsharedmemory/ipcsharedmemoryprovider.php',
'IpcMemcachedProvider' => 'backend/ipcmemcached/ipcmemcachedprovider.php', 'IpcMemcachedProvider' => 'backend/ipcmemcached/ipcmemcachedprovider.php',
'IpcWincacheProvider' => 'backend/ipcwincache/ipcwincacheprovider.php',
); );
static protected $devid; static protected $devid;
static protected $pid; static protected $pid;
......
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
// autoload.php @generated by Composer // autoload.php @generated by Composer
require_once __DIR__ . '/composer' . '/autoload_real.php'; require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitd6749fc2fb9944bbe86b2b7d79a7852f::getLoader(); return ComposerAutoloaderInit153a56a781a72686b71399955d98204f::getLoader();
...@@ -53,8 +53,9 @@ class ClassLoader ...@@ -53,8 +53,9 @@ class ClassLoader
private $useIncludePath = false; private $useIncludePath = false;
private $classMap = array(); private $classMap = array();
private $classMapAuthoritative = false; private $classMapAuthoritative = false;
private $missingClasses = array();
private $apcuPrefix;
public function getPrefixes() public function getPrefixes()
{ {
...@@ -271,6 +272,26 @@ class ClassLoader ...@@ -271,6 +272,26 @@ class ClassLoader
return $this->classMapAuthoritative; return $this->classMapAuthoritative;
} }
/**
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
*
* @param string|null $apcuPrefix
*/
public function setApcuPrefix($apcuPrefix)
{
$this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null;
}
/**
* The APCu prefix in use, or null if APCu caching is not enabled.
*
* @return string|null
*/
public function getApcuPrefix()
{
return $this->apcuPrefix;
}
/** /**
* Registers this instance as an autoloader. * Registers this instance as an autoloader.
* *
...@@ -313,29 +334,34 @@ class ClassLoader ...@@ -313,29 +334,34 @@ class ClassLoader
*/ */
public function findFile($class) public function findFile($class)
{ {
// work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731
if ('\\' == $class[0]) {
$class = substr($class, 1);
}
// class map lookup // class map lookup
if (isset($this->classMap[$class])) { if (isset($this->classMap[$class])) {
return $this->classMap[$class]; return $this->classMap[$class];
} }
if ($this->classMapAuthoritative) { if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
return false; return false;
} }
if (null !== $this->apcuPrefix) {
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
if ($hit) {
return $file;
}
}
$file = $this->findFileWithExtension($class, '.php'); $file = $this->findFileWithExtension($class, '.php');
// Search for Hack files if we are running on HHVM // Search for Hack files if we are running on HHVM
if ($file === null && defined('HHVM_VERSION')) { if (false === $file && defined('HHVM_VERSION')) {
$file = $this->findFileWithExtension($class, '.hh'); $file = $this->findFileWithExtension($class, '.hh');
} }
if ($file === null) { if (null !== $this->apcuPrefix) {
apcu_add($this->apcuPrefix.$class, $file);
}
if (false === $file) {
// Remember that this class does not exist. // Remember that this class does not exist.
return $this->classMap[$class] = false; $this->missingClasses[$class] = true;
} }
return $file; return $file;
...@@ -348,9 +374,13 @@ class ClassLoader ...@@ -348,9 +374,13 @@ class ClassLoader
$first = $class[0]; $first = $class[0];
if (isset($this->prefixLengthsPsr4[$first])) { if (isset($this->prefixLengthsPsr4[$first])) {
foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) { $subPath = $class;
if (0 === strpos($class, $prefix)) { while (false !== $lastPos = strrpos($subPath, '\\')) {
foreach ($this->prefixDirsPsr4[$prefix] as $dir) { $subPath = substr($subPath, 0, $lastPos);
$search = $subPath.'\\';
if (isset($this->prefixDirsPsr4[$search])) {
foreach ($this->prefixDirsPsr4[$search] as $dir) {
$length = $this->prefixLengthsPsr4[$first][$search];
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
return $file; return $file;
} }
...@@ -399,6 +429,8 @@ class ClassLoader ...@@ -399,6 +429,8 @@ class ClassLoader
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file; return $file;
} }
return false;
} }
} }
......
Copyright (c) 2016 Nils Adermann, Jordi Boggiano Copyright (c) Nils Adermann, Jordi Boggiano
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
......
...@@ -73,6 +73,7 @@ return array( ...@@ -73,6 +73,7 @@ return array(
'InterProcessData' => $baseDir . '/lib/core/interprocessdata.php', 'InterProcessData' => $baseDir . '/lib/core/interprocessdata.php',
'IpcMemcachedProvider' => $baseDir . '/backend/ipcmemcached/ipcmemcachedprovider.php', 'IpcMemcachedProvider' => $baseDir . '/backend/ipcmemcached/ipcmemcachedprovider.php',
'IpcSharedMemoryProvider' => $baseDir . '/backend/ipcsharedmemory/ipcsharedmemoryprovider.php', 'IpcSharedMemoryProvider' => $baseDir . '/backend/ipcsharedmemory/ipcsharedmemoryprovider.php',
'IpcWincacheProvider' => $baseDir . '/backend/ipcwincache/ipcwincache.php',
'ItemOperations' => $baseDir . '/lib/request/itemoperations.php', 'ItemOperations' => $baseDir . '/lib/request/itemoperations.php',
'KoeSignature' => $baseDir . '/lib/core/koesignatures.php', 'KoeSignature' => $baseDir . '/lib/core/koesignatures.php',
'KoeSignatures' => $baseDir . '/lib/core/koesignatures.php', 'KoeSignatures' => $baseDir . '/lib/core/koesignatures.php',
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer // autoload_real.php @generated by Composer
class ComposerAutoloaderInitd6749fc2fb9944bbe86b2b7d79a7852f class ComposerAutoloaderInit153a56a781a72686b71399955d98204f
{ {
private static $loader; private static $loader;
...@@ -19,15 +19,15 @@ class ComposerAutoloaderInitd6749fc2fb9944bbe86b2b7d79a7852f ...@@ -19,15 +19,15 @@ class ComposerAutoloaderInitd6749fc2fb9944bbe86b2b7d79a7852f
return self::$loader; return self::$loader;
} }
spl_autoload_register(array('ComposerAutoloaderInitd6749fc2fb9944bbe86b2b7d79a7852f', 'loadClassLoader'), true, true); spl_autoload_register(array('ComposerAutoloaderInit153a56a781a72686b71399955d98204f', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(); self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInitd6749fc2fb9944bbe86b2b7d79a7852f', 'loadClassLoader')); spl_autoload_unregister(array('ComposerAutoloaderInit153a56a781a72686b71399955d98204f', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION'); $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) { if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php'; require_once __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitd6749fc2fb9944bbe86b2b7d79a7852f::getInitializer($loader)); call_user_func(\Composer\Autoload\ComposerStaticInit153a56a781a72686b71399955d98204f::getInitializer($loader));
} else { } else {
$map = require __DIR__ . '/autoload_namespaces.php'; $map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) { foreach ($map as $namespace => $path) {
...@@ -48,19 +48,19 @@ class ComposerAutoloaderInitd6749fc2fb9944bbe86b2b7d79a7852f ...@@ -48,19 +48,19 @@ class ComposerAutoloaderInitd6749fc2fb9944bbe86b2b7d79a7852f
$loader->register(true); $loader->register(true);
if ($useStaticLoader) { if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInitd6749fc2fb9944bbe86b2b7d79a7852f::$files; $includeFiles = Composer\Autoload\ComposerStaticInit153a56a781a72686b71399955d98204f::$files;
} else { } else {
$includeFiles = require __DIR__ . '/autoload_files.php'; $includeFiles = require __DIR__ . '/autoload_files.php';
} }
foreach ($includeFiles as $fileIdentifier => $file) { foreach ($includeFiles as $fileIdentifier => $file) {
composerRequired6749fc2fb9944bbe86b2b7d79a7852f($fileIdentifier, $file); composerRequire153a56a781a72686b71399955d98204f($fileIdentifier, $file);
} }
return $loader; return $loader;
} }
} }
function composerRequired6749fc2fb9944bbe86b2b7d79a7852f($fileIdentifier, $file) function composerRequire153a56a781a72686b71399955d98204f($fileIdentifier, $file)
{ {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file; require $file;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
namespace Composer\Autoload; namespace Composer\Autoload;
class ComposerStaticInitd6749fc2fb9944bbe86b2b7d79a7852f class ComposerStaticInit153a56a781a72686b71399955d98204f
{ {
public static $files = array ( public static $files = array (
'158e247719544c05f5e89c414f630c24' => __DIR__ . '/../..' . '/version.php', '158e247719544c05f5e89c414f630c24' => __DIR__ . '/../..' . '/version.php',
...@@ -80,6 +80,7 @@ class ComposerStaticInitd6749fc2fb9944bbe86b2b7d79a7852f ...@@ -80,6 +80,7 @@ class ComposerStaticInitd6749fc2fb9944bbe86b2b7d79a7852f
'InterProcessData' => __DIR__ . '/../..' . '/lib/core/interprocessdata.php', 'InterProcessData' => __DIR__ . '/../..' . '/lib/core/interprocessdata.php',
'IpcMemcachedProvider' => __DIR__ . '/../..' . '/backend/ipcmemcached/ipcmemcachedprovider.php', 'IpcMemcachedProvider' => __DIR__ . '/../..' . '/backend/ipcmemcached/ipcmemcachedprovider.php',
'IpcSharedMemoryProvider' => __DIR__ . '/../..' . '/backend/ipcsharedmemory/ipcsharedmemoryprovider.php', 'IpcSharedMemoryProvider' => __DIR__ . '/../..' . '/backend/ipcsharedmemory/ipcsharedmemoryprovider.php',
'IpcWincacheProvider' => __DIR__ . '/../..' . '/backend/ipcwincache/ipcwincache.php',
'ItemOperations' => __DIR__ . '/../..' . '/lib/request/itemoperations.php', 'ItemOperations' => __DIR__ . '/../..' . '/lib/request/itemoperations.php',
'KoeSignature' => __DIR__ . '/../..' . '/lib/core/koesignatures.php', 'KoeSignature' => __DIR__ . '/../..' . '/lib/core/koesignatures.php',
'KoeSignatures' => __DIR__ . '/../..' . '/lib/core/koesignatures.php', 'KoeSignatures' => __DIR__ . '/../..' . '/lib/core/koesignatures.php',
...@@ -209,7 +210,7 @@ class ComposerStaticInitd6749fc2fb9944bbe86b2b7d79a7852f ...@@ -209,7 +210,7 @@ class ComposerStaticInitd6749fc2fb9944bbe86b2b7d79a7852f
public static function getInitializer(ClassLoader $loader) public static function getInitializer(ClassLoader $loader)
{ {
return \Closure::bind(function () use ($loader) { return \Closure::bind(function () use ($loader) {
$loader->classMap = ComposerStaticInitd6749fc2fb9944bbe86b2b7d79a7852f::$classMap; $loader->classMap = ComposerStaticInit153a56a781a72686b71399955d98204f::$classMap;
}, null, ClassLoader::class); }, null, ClassLoader::class);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment