Opened 11 months ago

Closed 11 months ago

Last modified 11 months ago

#329 closed defect (fixed)

require/include 缓存的bcompiler编码文件出错

Reported by: mark35 Owned by: moo
Priority: major Milestone: 3.1.1
Component: cacher Version: 3.0.3
Keywords: Cc:
Application: PHP Version: 5.3.27
Other Exts: SAPI: FastCGI
Probability: Always Blocked By:
Blocking:

Description

如果php文件是函数定义,那么bcompiler编码后首次加载正常,第二次加载(xcache缓存命中)后 require/inlude并无报错但函数并未创建。
如果是用class来定义,则无此问题。

demo:

a.php
<?php
require 'b-encoded.php';
b(); -- 二次刷新后会报函数b不存在
?>


b.php
<?php
function b() {

echo 'this is b.php';

}
echo '这儿一直都能显示的';
?>

用bencoder把b.php编译为b-encoded.php.
如果b.php是如下定义然后在a.php中调用,则二次刷新也正常
<?php
class B {

function b() {

echo 'this is class b';

}

}
?>

a.php
<?php
require 'b-encoded.php';
$b = new B;
$b->b(); 正常
?>

CentOS X64 v6.4
PHP 5.3.27
xcache 3.0.3

Change History (14)

comment:1 Changed 11 months ago by moo

  • Status changed from new to accepted

comment:2 Changed 11 months ago by mark35

经测试,使用APC 3.1.13没有发现类似bug

comment:3 Changed 11 months ago by moo

有点迟, 暂时不在 3.0.4/3.1.0 考虑内

comment:4 Changed 11 months ago by moo

  • Status changed from accepted to infoneeded

你的报告中并未提供任何生成 b-encoded.php 的方法, 也没提供 bcompiler 的版本

我尝试用了下 bcompiler/examples/bcompiler_compile.php, 该代码只处理 class 不处理 function

comment:5 Changed 11 months ago by moo

  • Status changed from infoneeded to assigned

假设用的是 bencoder-1.6 -o b-encoded.php b.php

comment:6 Changed 11 months ago by moo

  • Resolution set to worksforme
  • Status changed from assigned to closed

后台看到 b-encoded.php 没有被 xcache 缓存, 请检查您的测试操作是不是错了, 是不是用错文件了

comment:7 Changed 11 months ago by mark35

bcompiler:
http://pecl.php.net/package/bcompiler v1.0.2

bcompiler前端程序bencoder 可以处理function:
http://bencoder.urdada.net/bencoder

生成文件方法 生成文件名为 b-encoded.php:
# bencoder -f -t -b b.php

在xcache303的监控后台查看有此文件缓存 (非cli运行,而是web访问)

Last edited 11 months ago by mark35 (previous) (diff)

comment:8 Changed 11 months ago by moo

用同样的命令 依然无法重现. 确实用的非cli, 用fcgi 从web browser -> web server -> fcgi 如此反复访问

请提供最小的能重现问题的 ini 配置 以及任何可以让问题重现必要的东西. 可以尝试在一台新的机器把东西弄过去重现 就可以确定哪些是重现的必备因素

comment:9 Changed 11 months ago by mark35

换了台生产服务器,系统干净,问题依然

[root@jmis src]# php -v
PHP 5.3.27 (cli) (built: Aug 22 2013 21:55:34)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies

with XCache v3.0.3, Copyright (c) 2005-2013, by mOo
with XCache Cacher v3.0.3, Copyright (c) 2005-2013, by mOo



root@jmis src]# php -m
[PHP Modules]
bcompiler
bz2
Core
ctype
curl
date
dom
ereg
exif
fileinfo
filter
ftp
gd
hash
iconv
intl
json
libxml
mbstring
openssl
pcntl
pcre
PDO
pdo_pgsql
pgsql
posix
Reflection
session
SimpleXML
sockets
SPL
standard
sysvmsg
sysvsem
sysvshm
XCache
XCache Cacher
xml
xmlreader
xmlwriter
zip
zlib

[Zend Modules]
XCache
XCache Cacher



编译参数 config.nice:

#! /bin/sh
#
# Created by configure

'./configure' \
'--build=x86_64-redhat-linux-gnu' \
'--host=x86_64-redhat-linux-gnu' \
'--with-layout=GNU' \
'--with-libdir=lib64' \
'--prefix=/usr/local' \
'--exec-prefix=/usr/local' \
'--sysconfdir=/etc' \
'--libdir=/usr/local/lib64/php' \
'--sbindir=/usr/local/sbin' \
'--sharedstatedir=/usr/com' \
'--datadir=/usr/local/share' \
'--includedir=/usr/local/include' \
'--libexecdir=/usr/local/libexec' \
'--localstatedir=/var' \
'--mandir=/usr/local/share/man' \
'--infodir=/usr/local/share/info' \
'--with-config-file-path=/etc' \
'--with-config-file-scan-dir=/etc/php.d' \
'--with-pic' \
'--with-curl' \
'--with-freetype-dir' \
'--with-png-dir' \
'--with-gettext=shared' \
'--with-gmp=shared' \
'--with-iconv' \
'--with-jpeg-dir' \
'--with-png-dir' \
'--with-openssl' \
'--with-libxml-dir' \
'--with-pcre-regex' \
'--with-mcrypt=shared' \
'--with-zlib' \
'--with-pgsql=/usr/pgsql-9.2' \
'--with-pdo-pgsql=/usr/pgsql-9.2' \
'--with-pear' \
'--with-gd' \
'--enable-gd-native-ttf' \
'--enable-calendar=shared' \
'--enable-exif' \
'--enable-ftp' \
'--enable-sockets' \
'--enable-bcmath=shared' \
'--enable-pcntl' \
'--enable-intl' \
'--enable-mbstring' \
'--enable-zend-multibyte' \
'--enable-zip' \
'--with-bz2' \
'--without-unixODBC' \
'--enable-mbregex' \
'--enable-fpm' \
'--with-fpm-user=www' \
'--with-fpm-group=www' \
'--disable-tokenizer' \
'--disable-phar' \
'--without-sqlite3' \
'--without-pdo-sqlite' \
'--without-sqlite' \
'--enable-sysvsem' \
'--enable-sysvshm' \
'--enable-sysvmsg' \
'--disable-cgi' \
"$@"



php.ini:

[apc]
;extension=apc.so
apc.enabled=1
apc.shm_segments=1
apc.shm_size=64
apc.ttl=7200
apc.user_ttl=7200
apc.slam_defense=0
apc.enable_cli=0
apc.write_lock=on

[xcache-common]
extension = xcache.so

[xcache.admin]
xcache.admin.enable_auth = On
xcache.admin.user = "xxx"
xcache.admin.pass = "xxx"

[xcache]
xcache.shm_scheme = "mmap"
xcache.size = 64M
xcache.count = 4
xcache.slots = 8K
xcache.ttl = 900
xcache.gc_interval = 600

xcache.var_size = 0M
xcache.var_count = 4
xcache.var_slots = 16K
xcache.var_ttl = 60
xcache.var_maxttl = 86400
xcache.var_gc_interval = 300
xcache.var_namespace_mode = 0
xcache.var_namespace = ""
xcache.readonly_protection = On
xcache.mmap_path = "/tmp/xcache"
xcache.coredump_directory = ""
xcache.disable_on_crash = Off
xcache.experimental = Off
xcache.cacher = On
xcache.stat = On
xcache.optimizer = Off

[xcache.coverager]
xcache.coverager = Off
xcache.coverager_autostart = On
xcache.coveragedump_directory = ""



文件a.php:

<?php

require 'b.php';
require 'b-encoded.php';

$b = new B();
$b->b();

a();

die("test end;\n");



文件b.php:

<?php

function a()
{

echo "func a; \n";

}

class B
{

public function construct()
{
}
public function b()
{

echo "class B; \n";

}

}

?>



关闭xcache,或者使用apc, http访问a.php结果是:
class B; func a; test end;

打开xcache,第一次访问正常,第二次访问(有缓存)结果是:
class B;

并且日志中报错:
2013/10/21 20:53:33 [error] 20545#0: *25452 FastCGI sent in stderr: "PHP message: PHP Fatal error: Call to undefined function a() in /var/www/a.php on line 9"

php.ini配置改成如下,问题依旧
xcache.count = 1
xcache.readonly_protection = Off
xcache.mmap_path = "/dev/zero"

Last edited 11 months ago by mark35 (previous) (diff)

comment:10 Changed 11 months ago by moo

看了你的 version 输出, 猜测是载入方式不同. zend_extension=bcompiler.so 没问题
如果你用 extension=bcompiler.so, 可以试试调整顺序, 确保他在 extension=xcache.so 前面或者后面以便让 XCache 发现它的存在, 如果不行的话还是要改用 zend_extension=/path/to/bcompiler.so. 还请把结果反馈回来, 哪个配置方式可以哪个方式不行

comment:11 Changed 11 months ago by mark35

两台服务器上测试,结果与加载顺序无关。bcompiler如果用extension加载,出错;如果用zend_extension加载,正常。

comment:12 Changed 11 months ago by moo

  • Resolution worksforme deleted
  • Status changed from closed to new

comment:13 Changed 11 months ago by moo

  • Resolution set to fixed
  • Status changed from new to closed

In 1434:

fixed #329: compatbile with bcompiler

comment:14 Changed 11 months ago by moo

  • Milestone changed from undecided to 3.1.1
Note: See TracTickets for help on using tickets.