Skip to content

Fix APC tests and add APCu support #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
os: linux
dist: xenial
dist: focal
language: php

php:
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4
- nightly
- 7.4
- 8.0
- 8.1
- nightly

# run build against nightly but allow them to fail
jobs:
fast_finish: true
allow_failures:
- php: nightly
- php: 5.3
- php: 5.4
include:
- php: 5.3
dist: precise
- php: 5.4
dist: precise
dist: trusty
- php: 5.5
dist: trusty
- php: 5.6
dist: trusty
- php: 7.0
dist: xenial
- php: 7.1
dist: xenial
- php: 7.2
dist: xenial
- php: 7.3
dist: xenial

services:
- memcached
Expand All @@ -40,6 +48,8 @@ install:
# by default, --remote is not used on travis
- git submodule update --remote --force
- composer install --prefer-dist --no-progress --no-suggest -o
# Temporary, while Doctrine is not merged, it will avoid one error tasksTest
- echo 'error_reporting = E_ALL & ~E_DEPRECATED' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini

script:
- php data/bin/check_configuration.php
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ All the enhancements and BC breaks are listed in the [WHATS_NEW](https://github.

- [DIC](https://github.com/FriendsOfSymfony1/symfony1/wiki/ServiceContainer)
- Composer support
- PHP 7.2 support
- PHP 8.1 support
- performance boost
- new widgets & validators
- some tickets fixed from the symfony trac
Expand Down
2 changes: 1 addition & 1 deletion data/bin/check_configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function get_ini_path()
check(function_exists('posix_isatty'), 'The posix_isatty() is available', 'Install and enable the php_posix extension (used to colorized the CLI output)', false);

$accelerator =
(function_exists('apc_store') && ini_get('apc.enabled'))
((function_exists('apc_store') || function_exists('apcu_store')) && ini_get('apc.enabled'))
||
function_exists('eaccelerator_put') && ini_get('eaccelerator.enable')
||
Expand Down
6 changes: 6 additions & 0 deletions lib/addon/sfPager.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ protected function resetIterator()
*
* @see Iterator
*/
#[\ReturnTypeWillChange]
public function current()
{
if (!$this->isIteratorInitialized())
Expand All @@ -544,6 +545,7 @@ public function current()
*
* @see Iterator
*/
#[\ReturnTypeWillChange]
public function key()
{
if (!$this->isIteratorInitialized())
Expand All @@ -559,6 +561,7 @@ public function key()
*
* @see Iterator
*/
#[\ReturnTypeWillChange]
public function next()
{
if (!$this->isIteratorInitialized())
Expand All @@ -576,6 +579,7 @@ public function next()
*
* @see Iterator
*/
#[\ReturnTypeWillChange]
public function rewind()
{
if (!$this->isIteratorInitialized())
Expand All @@ -593,6 +597,7 @@ public function rewind()
*
* @see Iterator
*/
#[\ReturnTypeWillChange]
public function valid()
{
if (!$this->isIteratorInitialized())
Expand All @@ -608,6 +613,7 @@ public function valid()
*
* @see Countable
*/
#[\ReturnTypeWillChange]
public function count()
{
return $this->getNbResults();
Expand Down
1 change: 1 addition & 0 deletions lib/autoload/sfCoreAutoload.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ static public function make()
'sfcoreautoload' => 'autoload/sfCoreAutoload.class.php',
'sfsimpleautoload' => 'autoload/sfSimpleAutoload.class.php',
'sfapccache' => 'cache/sfAPCCache.class.php',
'sfapcucache' => 'cache/sfAPCuCache.class.php',
'sfcache' => 'cache/sfCache.class.php',
'sfeacceleratorcache' => 'cache/sfEAcceleratorCache.class.php',
'sffilecache' => 'cache/sfFileCache.class.php',
Expand Down
221 changes: 221 additions & 0 deletions lib/cache/sfAPCuCache.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
<?php

/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/**
* Cache class that stores cached content in APCu.
*
* @package symfony
* @subpackage cache
* @author Fabien Potencier <[email protected]>
* @author Paulo M
* @version SVN: $Id$
*/
class sfAPCuCache extends sfCache
{
protected $enabled;

/**
* Initializes this sfCache instance.
*
* Available options:
*
* * see sfCache for options available for all drivers
*
* @see sfCache
* @inheritdoc
*/
public function initialize($options = array())
{
parent::initialize($options);

$this->enabled = function_exists('apcu_store') && ini_get('apc.enabled');
}

/**
* @see sfCache
* @inheritdoc
*/
public function get($key, $default = null)
{
if (!$this->enabled)
{
return $default;
}

$value = $this->fetch($this->getOption('prefix').$key, $has);

return $has ? $value : $default;
}

/**
* @see sfCache
* @inheritdoc
*/
public function has($key)
{
if (!$this->enabled)
{
return false;
}

$this->fetch($this->getOption('prefix').$key, $has);

return $has;
}

private function fetch($key, &$success)
{
$has = null;
$value = apcu_fetch($key, $has);
// the second argument was added in APC 3.0.17. If it is still null we fall back to the value returned
if (null !== $has)
{
$success = $has;
}
else
{
$success = $value !== false;
}

return $value;
}


/**
* @see sfCache
* @inheritdoc
*/
public function set($key, $data, $lifetime = null)
{
if (!$this->enabled)
{
return true;
}

return apcu_store($this->getOption('prefix').$key, $data, $this->getLifetime($lifetime));
}

/**
* @see sfCache
* @inheritdoc
*/
public function remove($key)
{
if (!$this->enabled)
{
return true;
}

return apcu_delete($this->getOption('prefix').$key);
}

/**
* @see sfCache
* @inheritdoc
*/
public function clean($mode = sfCache::ALL)
{
if (!$this->enabled)
{
return true;
}

if (sfCache::ALL === $mode)
{
return apcu_clear_cache();
}
}

/**
* @see sfCache
* @inheritdoc
*/
public function getLastModified($key)
{
if ($info = $this->getCacheInfo($key))
{
return $info['creation_time'] + $info['ttl'] > time() ? $info['mtime'] : 0;
}

return 0;
}

/**
* @see sfCache
* @inheritdoc
*/
public function getTimeout($key)
{
if ($info = $this->getCacheInfo($key))
{
return $info['creation_time'] + $info['ttl'] > time() ? $info['creation_time'] + $info['ttl'] : 0;
}

return 0;
}

/**
* @see sfCache
* @inheritdoc
*/
public function removePattern($pattern)
{
if (!$this->enabled)
{
return true;
}

$infos = apcu_cache_info();
if (!is_array($infos['cache_list']))
{
return;
}

$regexp = self::patternToRegexp($this->getOption('prefix').$pattern);

foreach ($infos['cache_list'] as $info)
{
if (preg_match($regexp, $info['info']))
{
apcu_delete($info['info']);
}
}
}

/**
* Gets the cache info
*
* @param string $key The cache key
*
* @return string
*/
protected function getCacheInfo($key)
{
if (!$this->enabled)
{
return false;
}

$infos = apcu_cache_info();

if (is_array($infos['cache_list']))
{
foreach ($infos['cache_list'] as $info)
{
if ($this->getOption('prefix').$key == $info['info'])
{
return $info;
}
}
}

return null;
}
}
10 changes: 9 additions & 1 deletion lib/cache/sfFileCache.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,15 @@ protected function read($path, $type = self::READ_DATA)
fseek($fp, 0, SEEK_END);
$length = ftell($fp) - 24;
fseek($fp, 24);
$data[self::READ_DATA] = @fread($fp, $length);

if ($length > 0)
{
$data[self::READ_DATA] = @fread($fp, $length);
}
else
{
$data[self::READ_DATA] = '';
}
}
}
else
Expand Down
3 changes: 3 additions & 0 deletions lib/database/sfMySQLiDatabase.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class sfMySQLiDatabase extends sfMySQLDatabase
*/
protected function getConnectMethod($persistent)
{
// PHP 8.1 Activate Exception per default, revert behavior to "return false"
mysqli_report(MYSQLI_REPORT_OFF);

return 'mysqli_connect';
}

Expand Down
Loading