After flawless testing on my dev machine (Vista x64 SP2, IIS 7) we installed wincache on the production server last night, and got a very strange result. We spent most of the morning testing and troubleshooting before we pinpointed what was happening.
We have the code
require_once('library/common.php') or require_once('common.php') in almost all of our files, and that seems to work fine. However, in one file we have it like this:
Because the file is called in different ways. The problem is that the primary file has the require_once('library/common.php') in it as well (sometimes that file is called alone, which is why we have the documet_root) and
what ends up occurring is common.php is loaded twice. I've done many tests and I am certain that this is happening. That's a problem because common.php has certain functions that cannot be run twice. We can probably work around this, but I feel we might
just pull it. I've disabled wincache in runtime and it stops this double loading.
Oh, and it's probably not hard to guess, but it's file cache specifically, not the op code cache.
One more thing, we have several dev sites on this server (on different ports, 90, 91, etc..) and it only does this on the primary (80) and on none of the other dev machines.
I just realized something. The way we know it's loaded twice is we put code at the top of common.php that displays on the screen (can't use the debugger on the live site) and it displays twice at the top....why don't we get "cannot redeclare function" error
messages?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<?php
require_once 'library/common_test.php';
require_once 'library/test_code.php';
Thanks for the repro. I tried it out but I couldn't repro it on my machine. Any chance that multiple copies of common_test.php are present on the machine? Can you pls set wincache.debuglevel to 301 in php.ini, recycle php process, run dgbview (google and download
if you don't have it), run script again and paste the debug output you see in dbgview?
[7220] WINCACHE: zend_resolve_path called for c:\inetpub\wwwroot\test.php
[7220] WINCACHE: zend_stream_open_function called for c:\inetpub\wwwroot\test.php
[7220] WINCACHE: compile_file called for c:\inetpub\wwwroot\test.php
[7220] WINCACHE: zend_resolve_path called for library/common_test.php
[7220] WINCACHE: relative path library/common_test.php is resolved path as C:\Inetpub\wwwroot\library\common_test.php
[7220] WINCACHE: zend_stream_open_function called for C:\Inetpub\wwwroot\library\common_test.php
[7220] WINCACHE: compile_file called for C:\Inetpub\wwwroot\library\common_test.php
[7220] WINCACHE: zend_resolve_path called for library/test_code.php
[7220] WINCACHE: relative path library/test_code.php is resolved path as C:\Inetpub\wwwroot\library\test_code.php
[7220] WINCACHE: zend_stream_open_function called for C:\Inetpub\wwwroot\library\test_code.php
[7220] WINCACHE: compile_file called for C:\Inetpub\wwwroot\library\test_code.php
[7220] WINCACHE: zend_resolve_path called for c:\inetpub\wwwroot/library/common_test.php
[7220] WINCACHE: zend_stream_open_function called for c:\inetpub\wwwroot\library\common_test.php
[7220] WINCACHE: compile_file called for c:\inetpub\wwwroot\library\common_test.php
Thanks for sending this trace. Looks like both times path correctly resolved to the same file. Thing which look suspicious is the difference in casing of "C:\Inetpub" part. I will try with different casing on my test machine and respond back.
Many thanks for reporting this bug. We are able to have a small repro here, A bug has been filed in internal bug database. We will fix it in the next release.
laurin1
257 Posts
Require_once Requires File Twice Under Wincache
Sep 11, 2009 07:37 PM|LINK
After flawless testing on my dev machine (Vista x64 SP2, IIS 7) we installed wincache on the production server last night, and got a very strange result. We spent most of the morning testing and troubleshooting before we pinpointed what was happening.
We have the code
require_once('library/common.php') or require_once('common.php') in almost all of our files, and that seems to work fine. However, in one file we have it like this:
require_once $_SERVER['DOCUMENT_ROOT'].'/library/common.php';
Because the file is called in different ways. The problem is that the primary file has the require_once('library/common.php') in it as well (sometimes that file is called alone, which is why we have the documet_root) and what ends up occurring is common.php is loaded twice. I've done many tests and I am certain that this is happening. That's a problem because common.php has certain functions that cannot be run twice. We can probably work around this, but I feel we might just pull it. I've disabled wincache in runtime and it stops this double loading.
Oh, and it's probably not hard to guess, but it's file cache specifically, not the op code cache.
One more thing, we have several dev sites on this server (on different ports, 90, 91, etc..) and it only does this on the primary (80) and on none of the other dev machines.
PHP wincache microsoft
laurin1
257 Posts
Re: Require_once Requires File Twice Under Wincache
Sep 11, 2009 07:56 PM|LINK
I just realized something. The way we know it's loaded twice is we put code at the top of common.php that displays on the screen (can't use the debugger on the live site) and it displays twice at the top....why don't we get "cannot redeclare function" error messages?
don.raman
1207 Posts
Microsoft
Moderator
Re: Require_once Requires File Twice Under Wincache
Sep 11, 2009 08:15 PM|LINK
Is it possible for you to give a small PHP code so that we can reproduce the problem at our end please?
Thanks,
Don.
laurin1
257 Posts
Re: Require_once Requires File Twice Under Wincache
Sep 11, 2009 08:41 PM|LINK
well, let's see....
test.php
{
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<?php
require_once 'library/common_test.php';
require_once 'library/test_code.php';
?>
<head>
<title>Test</title>
</head>
<body>
</body>
</html>
}
common_test.php
{
<?php
echo 'test';
?>
}
test_code.php
{
<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/library/common_test.php';
?>
}
The result with file cache enabled on my production server (Windows 2003 SP3, IIS 6) is
testtest
with file cache disabled or on my dev machine, the result is
test
ksingla
1138 Posts
Microsoft
Re: Require_once Requires File Twice Under Wincache
Sep 11, 2009 09:39 PM|LINK
Hi,
Thanks for the repro. I tried it out but I couldn't repro it on my machine. Any chance that multiple copies of common_test.php are present on the machine? Can you pls set wincache.debuglevel to 301 in php.ini, recycle php process, run dgbview (google and download if you don't have it), run script again and paste the debug output you see in dbgview?
Thanks,
Kanwal
laurin1
257 Posts
Re: Require_once Requires File Twice Under Wincache
Sep 12, 2009 09:53 PM|LINK
I am not really sure how to use dbgview in this manner, but I'll try.
laurin1
257 Posts
Re: Require_once Requires File Twice Under Wincache
Sep 12, 2009 10:00 PM|LINK
I don't know how to use dbgview. I've done everything you ask, but nothing is happening with debugview.
laurin1
257 Posts
Re: Require_once Requires File Twice Under Wincache
Sep 12, 2009 10:03 PM|LINK
Had to turn on Capture Global Win32:
[7220] WINCACHE: zend_resolve_path called for c:\inetpub\wwwroot\test.php
[7220] WINCACHE: zend_stream_open_function called for c:\inetpub\wwwroot\test.php
[7220] WINCACHE: compile_file called for c:\inetpub\wwwroot\test.php
[7220] WINCACHE: zend_resolve_path called for library/common_test.php
[7220] WINCACHE: relative path library/common_test.php is resolved path as C:\Inetpub\wwwroot\library\common_test.php
[7220] WINCACHE: zend_stream_open_function called for C:\Inetpub\wwwroot\library\common_test.php
[7220] WINCACHE: compile_file called for C:\Inetpub\wwwroot\library\common_test.php
[7220] WINCACHE: zend_resolve_path called for library/test_code.php
[7220] WINCACHE: relative path library/test_code.php is resolved path as C:\Inetpub\wwwroot\library\test_code.php
[7220] WINCACHE: zend_stream_open_function called for C:\Inetpub\wwwroot\library\test_code.php
[7220] WINCACHE: compile_file called for C:\Inetpub\wwwroot\library\test_code.php
[7220] WINCACHE: zend_resolve_path called for c:\inetpub\wwwroot/library/common_test.php
[7220] WINCACHE: zend_stream_open_function called for c:\inetpub\wwwroot\library\common_test.php
[7220] WINCACHE: compile_file called for c:\inetpub\wwwroot\library\common_test.php
ksingla
1138 Posts
Microsoft
Re: Require_once Requires File Twice Under Wincache
Sep 13, 2009 07:15 PM|LINK
Hi,
Thanks for sending this trace. Looks like both times path correctly resolved to the same file. Thing which look suspicious is the difference in casing of "C:\Inetpub" part. I will try with different casing on my test machine and respond back.
Thanks,
Kanwal
don.raman
1207 Posts
Microsoft
Moderator
Re: Require_once Requires File Twice Under Wincache
Sep 15, 2009 06:11 PM|LINK
Many thanks for reporting this bug. We are able to have a small repro here, A bug has been filed in internal bug database. We will fix it in the next release.
Again thanks for all the time in reporting this.
Don.