Partner and Community Forums
Windows Cache Extension for PHP
Require_once Requires File Twice Under Wincache
Last post Dec 03, 2009 09:50 AM by don.raman
Sep 11, 2009 08:37 PM|laurin1|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:
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.
Sep 11, 2009 08:56 PM|laurin1|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
Sep 11, 2009 09:15 PM|don.raman|LINK
Is it possible for you to give a small PHP code so that we can reproduce the problem at our end please?
Sep 11, 2009 09:41 PM|laurin1|LINK
well, let's see....
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
The result with file cache enabled on my production server (Windows 2003 SP3, IIS 6) is
with file cache disabled or on my dev machine, the result is
Sep 11, 2009 10:39 PM|ksingla|LINK
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?
Sep 12, 2009 10:53 PM|laurin1|LINK
I am not really sure how to use dbgview in this manner, but I'll try.
Sep 12, 2009 11:00 PM|laurin1|LINK
I don't know how to use dbgview. I've done everything you ask, but nothing is happening with debugview.
Sep 12, 2009 11:03 PM|laurin1|LINK
Had to turn on Capture Global Win32:
 WINCACHE: zend_resolve_path called for c:\inetpub\wwwroot\test.php
 WINCACHE: zend_stream_open_function called for c:\inetpub\wwwroot\test.php
 WINCACHE: compile_file called for c:\inetpub\wwwroot\test.php
 WINCACHE: zend_resolve_path called for library/common_test.php
 WINCACHE: relative path library/common_test.php is resolved path as C:\Inetpub\wwwroot\library\common_test.php
 WINCACHE: zend_stream_open_function called for C:\Inetpub\wwwroot\library\common_test.php
 WINCACHE: compile_file called for C:\Inetpub\wwwroot\library\common_test.php
 WINCACHE: zend_resolve_path called for library/test_code.php
 WINCACHE: relative path library/test_code.php is resolved path as C:\Inetpub\wwwroot\library\test_code.php
 WINCACHE: zend_stream_open_function called for C:\Inetpub\wwwroot\library\test_code.php
 WINCACHE: compile_file called for C:\Inetpub\wwwroot\library\test_code.php
 WINCACHE: zend_resolve_path called for c:\inetpub\wwwroot/library/common_test.php
 WINCACHE: zend_stream_open_function called for c:\inetpub\wwwroot\library\common_test.php
 WINCACHE: compile_file called for c:\inetpub\wwwroot\library\common_test.php
Sep 13, 2009 08:15 PM|ksingla|LINK
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.
Sep 15, 2009 07:11 PM|don.raman|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.
Sep 15, 2009 07:13 PM|laurin1|LINK
Glad I could help.
I may have another similar issue occurring right now, or it might the same issue. About to do some testing.
Sep 16, 2009 07:37 PM|laurin1|LINK
Well, we've gone about as far as we can with this. It continues to to load certain files twice and it's hard to determine why now. It only happens on our production server, and therefore is difficult to troubleshoot. We are removing it and may try again
with further releases, but it's really causing us a lot of trouble.
One odd thing was when, I disabled the opcode cache via ini_set and the function that it was duplicating, stopped working altogether (it's an ajax call using Scriptaculous and loads a list of names.)
Sep 16, 2009 09:22 PM|don.raman|LINK
Can you mail me back at don(dot)raman(at)microsoft(dot)com. We would like to help you in whatever way we could.
Oct 23, 2009 04:16 AM|laurin1|LINK
Call me paranoid, but I am deploying this tonight and just want to make sure. The patch you sent me for this is incorporated in the 1.0 RC, correct?
Oct 23, 2009 04:17 AM|don.raman|LINK
Yes, it is.
Oct 23, 2009 04:22 AM|laurin1|LINK
Dec 03, 2009 06:23 AM|laurin1|LINK
Ah! We installed 1.0 RTW last week, and guess what we found today?! This bug is back. Did the fix not get committed to the main branch or what?
Dec 03, 2009 07:51 AM|don.raman|LINK
This should be fixed in RTW release. I did test it and also the script you provided in this forum is part of my regression suite. Are you sure you are using the RTW bits?
We did fix couple of other bugs in the same codepath, but I don't think we regressed this. Can you test the script you provided in this post and get back to me.
Dec 03, 2009 09:16 AM|don.raman|LINK
Sorry, this was a blunder on my side and I take all the responsibility. Seems like this is broken in PHP5.3 and works well on PHP5.2. I am working on a fix. I am extremely sorry for this. I will send you the privates once I have a fix.
Dec 03, 2009 09:50 AM|don.raman|LINK
I have fixed it. I will send you the privates over email. I am doing some more test now. Again I am sorry for this blunder.
Thanks for reporting this,
PS: This is specific to PHP5.3. If anyone else is running into similar problem, please contact me. We are also planning to do a 1.0.1 upodate soon (probably early next year).