Поддержка SMF 2.0 Zned opcache и APCu под PHP 5.5+

Автор crazyASD, 14 марта 2016, 17:48:53

« назад - далее »

0 Пользователи и 1 гость просматривают эту тему.

crazyASD

Сервер с PHP 5.6.18 + APCu + Opcode cache. SMF 2.0.11 не находит ни одного акселератора, сообщая об их отсутсвии, следовательно пишет кэш в свою папку на SSD.
Поставил Xcache, но он не настолько торт, как Zend Opcache.
Вопрос, как заставить SMF увидеть APcu?

UPD. Сам спросил, сам отвечаю.

Поддержка APCu

Load.php
// This is the free APC from PECL.
elseif (function_exists('apc_fetch'))
$value = apc_fetch($key . 'smf');
меняем на:
// This is the free APC from PECL.
 elseif (function_exists('apcu_fetch'))
 $value = apcu_fetch($key . 'smf');

Поддержка Zend opcode cache

Load.php
Находим:
// Otherwise it's SMF data!
elseif (file_exists($cachedir . '/data_' . $key . '.php') && filesize($cachedir . '/data_' . $key . '.php') > 10)
{
Добавляем после:
// Work around Zend's opcode caching (PHP 5.5+), they would cache older files for a couple of seconds
// causing newer files to take effect a while later.
if (function_exists('opcache_invalidate'))
opcache_invalidate($cachedir . '/data_' . $key . '.php', true);
Дичайше радуемся жизни.
Сон разума порождает монстров
Wordpress - рулит!  SMF 2.0.11

kak2z

Цитата: crazyASD от 14 марта 2016, 17:48:53Сервер с PHP 5.6.18 + APCu + Opcode cache. SMF 2.0.11 не находит ни одного акселератора, сообщая об их отсутсвии, следовательно пишет кэш в свою папку на SSD.
Поставил Xcache, но он не настолько торт, как Zend Opcache.
Вопрос, как заставить SMF увидеть APcu?
ПХП лучше взять ниже чем 5.6)) а то ругаться может))
а просто APC там нет? Только APCu ?
Если нужно что то исправить, обновить, переставить, настроить, сделать форум заново - пишите в ЛС)

crazyASD

Цитата: kak2z от 14 марта 2016, 17:52:29ПХП лучше взять ниже чем 5.6)) а то ругаться может))
а просто APC там нет? Только APCu ?
1. Не ругается, вся ругань была исправлена (а её было пару мест).
2. Начиная с PHP 5.5.* APC не поддерживается и считается устаревшим.
UPD. После перезагрузки сервера форум получил какой-то дичайший приход в скорости загрузки страниц, я аж испугался )
Сон разума порождает монстров
Wordpress - рулит!  SMF 2.0.11

digger®

Цитата: crazyASD от 14 марта 2016, 17:48:53Добавляем после:
// Work around Zend's opcode caching (PHP 5.5+), they would cache older files for a couple of seconds
// causing newer files to take effect a while later.
 if (function_exists('opcache_invalidate'))
 opcache_invalidate($cachedir . '/data_' . $key . '.php', true);
Дичайше радуемся жизни.
Смысл этого кода разъясните.

crazyASD

Цитата: digger® от 14 марта 2016, 18:22:26Смысл этого кода разъясните.
ЦитироватьIn admin area after any settings update i see old values in form input fields. But after refreshing page 1-2 seconds i see actual settings values. It scares users.

To repeat it need PHP + file opcache extension and SMF 2.0.* file caching.

When SMF used file caching and PHP has file opcache extensions (Zend Opcache, APC, XCache and other) function cache_get_data return old (invalid) data from sources/Load.php:
This is due to the fact that opcache invalidate file cache by default every 2 seconds
Обсуждение проблемы в официальном Github SMF
Сон разума порождает монстров
Wordpress - рулит!  SMF 2.0.11

digger®

Цитата: crazyASD от 14 марта 2016, 17:48:53Load.php
// This is the free APC from PECL.
elseif (function_exists('apc_fetch'))
$value = apc_fetch($key . 'smf');
меняем на:
// This is the free APC from PECL.
 elseif (function_exists('apcu_fetch'))
 $value = apcu_fetch($key . 'smf');
Наверное, нужно и все вызовы функций apс_ в коде поменять на apcu_ ? А иначе, у вас просто галка в админке появилась, которая ничего не делает?

crazyASD

Цитата: digger® от 14 марта 2016, 18:29:17Наверное, нужно и все вызовы функций apс_ в коде поменять на apcu_ ? А иначе, у вас просто галка в админке появилась, которая ничего не делает?
А кагбе больше нигде вызова этой функции и нет.
Есть директива в ManageServer.php:  

elseif (function_exists('apc_store'))
        $detected = 'APC';

и Load.php

// Alternative PHP Cache, ahoy!
elseif (function_exists('apc_store'))
{
// An extended key is needed to counteract a bug in APC.
if ($value === null)
apc_delete($key . 'smf');
else
apc_store($key . 'smf', $value, $ttl);
}

  if (function_exists('apc_delete_file'))
        @apcu_delete_file($cachedir . '/data_' . $key . '.php');


Но они итак обрабатываются без ошибок, потому что APCu это тот же APC, только с отрезанным кэшем опкодов.
Хотя ради прикола можно и поменять все эти apc_ на apcu_
Сон разума порождает монстров
Wordpress - рулит!  SMF 2.0.11

Yarik

Цитата: crazyASD от 14 марта 2016, 18:14:39UPD. После перезагрузки сервера форум получил какой-то дичайший приход в скорости загрузки страниц, я аж испугался )
А форум тот что в профиле?А то хотел глянуть а там
ЦитироватьXCache is not configured correctly. Please refer to https://wordpress.org/extend/plugins/xcache/installation/ for instructions.

Yworld_garry

Цитата: Stalker от 14 марта 2016, 18:44:19А форум тот что в профиле?А то хотел глянуть а там
не это WP в корне рухнул, форум ниже, но что то мне подсказывает, что после перезагрузки сервака, какое то время все летает.

crazyASD

Цитата: Stalker от 14 марта 2016, 18:44:19А форум тот что в профиле?А то хотел глянуть а там
Цитата: Yworld_garry от 14 марта 2016, 18:50:01не это WP в корне рухнул, форум ниже, но что то мне подсказывает, что после перезагрузки сервака, какое то время все летает.
Fixed now ;)
Сон разума порождает монстров
Wordpress - рулит!  SMF 2.0.11

Akrobs

Цитата: crazyASD от 14 марта 2016, 18:58:29Fixed now ;)
Доброго дня. Сделал как вы написал, но почему-то Zend's opcode caching так и не появился в админке.

crazyASD

Цитата: Akrobs от 19 марта 2016, 18:06:40Доброго дня. Сделал как вы написал, но почему-то Zend's opcode caching так и не появился в админке.
А Zend и не появится, он опкоды кэширует безотносительно включения в настройках PHP, описанная здесь процедура нужна для включения кэширования пользовательских данных через APCu, чтобы форум не писал в директорию Cache временные файлы, и не убивал SSD.
Сон разума порождает монстров
Wordpress - рулит!  SMF 2.0.11

Delysid

Using information I found in SMF 2.1 Beta 3 I have been able to get SMF 2.0.14 to recognise and use the APCu accelerator in PHP 7.0/7.1 by making the following code changes:

In ./Sources/Load.php
Find:
Code: [Select]
// Alternative PHP Cache, ahoy!
elseif (function_exists('apc_store'))
{
// An extended key is needed to counteract a bug in APC.
if ($value === null)
apc_delete($key . 'smf');
else
apc_store($key . 'smf', $value, $ttl);
}
Add After:
Code: [Select]
elseif (function_exists('apcu_store'))
{
// An extended key is needed to counteract a bug in APC.
if ($value === null)
apcu_delete($key . 'smf');
else
apcu_store($key . 'smf', $value, $ttl);
}

Find:
Code: [Select]
if (function_exists('apc_delete_file'))
@apc_delete_file($cachedir . '/data_' . $key . '.php');
Add After
Code: [Select]
if (function_exists('apcu_delete_file'))
@apcu_delete_file($cachedir . '/data_' . $key . '.php');

Find:
Code: [Select]
// This is the free APC from PECL.
elseif (function_exists('apc_fetch'))
$value = apc_fetch($key . 'smf');
Add After:
Code: [Select]
// This is the free APCu from PECL.
elseif (function_exists('apcu_fetch'))
$value = apcu_fetch($key . 'smf');

In ./Sources/ManageServer.php
Find:
Code: [Select]
elseif (function_exists('apc_store'))
$detected = 'APC';
Add After:
Code: [Select]
elseif (function_exists('apcu_store'))
$detected = 'APCu';


In ./Themes/default/languages/ManageSettings.english.php
Find:
Code: [Select]
<li>APC</li>
Add After:
Code: [Select]
<li>APCu</li>

Find:
Code: [Select]
$txt['detected_APC'] = '<strong style="color: green">SMF has detected that your server has APC installed.</strong>';
Add After:
Code: [Select]
$txt['detected_APCu'] = '<strong style="color: green">SMF has detected that your server has APCu installed.</strong>';

 ;)

Delysid

// Otherwise it's SMF data!
if (file_exists($cachedir . '/data_' . $key . '.php') && filesize($cachedir . '/data_' . $key . '.php') > 10)
{
// Work around Zend's opcode caching (PHP 5.5+), they would cache older files for a couple of seconds
// causing newer files to take effect a while later.
if (function_exists('opcache_invalidate'))
opcache_invalidate($cachedir . '/data_' . $key . '.php', true);
// php will cache file_exists et all, we can't 100% depend on its results so proceed with caution
@include($cachedir . '/data_' . $key . '.php');
if (!empty($expired) && isset($value))

На мой взгляд очень важный фикс чтобы взлететь накрутив где возможно на хостингах параметры Zend's opcode..  :)