php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76529 php-cgi: -C option ignored
Submitted: 2018-06-25 20:36 UTC Modified: 2018-06-27 20:20 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: shhsu at microsoft dot com Assigned:
Status: Verified Package: *General Issues
PHP Version: 7.2.7 OS: Windows
Private report: No CVE-ID: None
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
29 - 12 = ?
Subscribe to this entry?

 
 [2018-06-25 20:36 UTC] shhsu at microsoft dot com
Description:
------------
Hi

We are trying to benchmark PHP performance under IIS. We noticed that PHP is trying to chdir to script directory and that is causing a lot of contention because it's IO bound.

To workaround this. I tried to pass "-C" option to php-cgi.exe. (Process run as: "php-cgi.exe -C" However, I am still observing chdir taking place.

P.S. I noticed that php_execute_script (https://github.com/php/php-src/blob/5f58f5ccf0909a90baef1280c3826f96b8e133ee/main/main.c#L2496) gets executed before zend_first_try (https://github.com/php/php-src/blob/5f58f5ccf0909a90baef1280c3826f96b8e133ee/sapi/cgi/cgi_main.c#L2356) where the -C option is processed. Not sure if this is by design.

Test script:
---------------
Setup PHP for IIS. Add the following configuration 
</system.webServer>
        <fastCgi>
            <application fullPath="C:\php-7.2.7-nts-Win32-VC15\php-cgi.exe" arguments="-C" maxInstances="10" instanceMaxRequests="10000000" queueLength="10000">
                <environmentVariables>
                    <environmentVariable name="PHP_FCGI_MAX_REQUESTS" value="10000000" />
                    <environmentVariable name="PHPRC" value="C:\php-7.2.7-nts-Win32-VC15" />
                </environmentVariables>
            </application>
        </fastCgi>
</system.webServer>



<location path="" overrideMode="Allow">
        <system.webServer>
            <handlers accessPolicy="Read, Script">
                <add name="PHP-iisfcgi" path="*.php" verb="GET,HEAD,POST" modules="FastCgiModule" scriptProcessor="C:\php-7.2.7-nts-Win32-VC15\php-cgi.exe|-C" resourceType="Either" />
</system.webServer>
....
</location>

Expected result:
----------------
If I execute php-cgi with -C, no chdir to script path should take place

Actual result:
--------------
chdir to script path

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-06-27 20:20 UTC] ab@php.net
-Status: Open +Status: Verified
 [2018-06-27 20:20 UTC] ab@php.net
Thanks for the report. You're rigt, -C is only taken in account when php-cgi.exe is run on console, like the most of the options. It seems to be indeed by design, as the surrounding condition is "if (!cgi && !fastcgi) {". This likely to be fixed easily by moving the case a couple of lines above into another switch https://github.com/php/php-src/blob/5f58f5ccf0909a90baef1280c3826f96b8e133ee/sapi/cgi/cgi_main.c#L2293 . It seems to be a crossplatform behavior, not IIS specific.

I'm a bit reluctant on changing this right away, because there might be other implication in performance and compatibility with some legacy PHP code. Right now the 7.3 feature freeze is less than a week away and changing this behavior might have a beyond impact. It would be good to hear more opinions and to consider a fix for the next minor version.

Thanks.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 08:01:35 2025 UTC