#40758 [NEW]: Test fcgi_is_fastcgi() is wrong on windows

Ask a Question related to PHP Bugs, Design and Development.

  1. #1

    Default #40758 [NEW]: Test fcgi_is_fastcgi() is wrong on windows

    From: jostb2345 at yahoo dot com
    Operating system: Windows (all versions)
    PHP version: 5.2.1
    PHP Bug Type: Reproducible crash
    Bug description: Test fcgi_is_fastcgi() is wrong on windows

    Description:
    ------------
    On windows, php 5.2.0 and above the following code (written in
    pseudo-code) doesn't work anymore:

    socket = socket(AF_INET, ...);
    bind(socket, ...);
    listen(socket, ...);
    outputHandle=GetStdHandle(...);
    inputHandle=socket;
    CreateProcess(...,"php-cgi.exe", ..., IOHandles);

    The problem is that "is_fastcgi" is only set if the OutputHandle and
    ErrorHandle are invalid. If both are invalid, InputHandle is assumed to be
    a named pipe.

    The Unix version still uses the old (correct) code.

    To correct this problem either the old FCGI_isfcgi() should be used or the
    test must be dublicated. See procedures:

    int fcgi_init(void);
    int fcgi_is_fastcgi(void);


    Regards,
    Jost Boekemeier




    Reproduce code:
    ---------------
    See above. If necessary I can provide a test program.



    --
    Edit bug report at [url]http://bugs.php.net/?id=40758&edit=1[/url]
    --
    Try a CVS snapshot (PHP 4.4): [url]http://bugs.php.net/fix.php?id=40758&r=trysnapshot44[/url]
    Try a CVS snapshot (PHP 5.2): [url]http://bugs.php.net/fix.php?id=40758&r=trysnapshot52[/url]
    Try a CVS snapshot (PHP 6.0): [url]http://bugs.php.net/fix.php?id=40758&r=trysnapshot60[/url]
    Fixed in CVS: [url]http://bugs.php.net/fix.php?id=40758&r=fixedcvs[/url]
    Fixed in release: [url]http://bugs.php.net/fix.php?id=40758&r=alreadyfixed[/url]
    Need backtrace: [url]http://bugs.php.net/fix.php?id=40758&r=needtrace[/url]
    Need Reproduce Script: [url]http://bugs.php.net/fix.php?id=40758&r=needscript[/url]
    Try newer version: [url]http://bugs.php.net/fix.php?id=40758&r=oldversion[/url]
    Not developer issue: [url]http://bugs.php.net/fix.php?id=40758&r=support[/url]
    Expected behavior: [url]http://bugs.php.net/fix.php?id=40758&r=notwrong[/url]
    Not enough info: [url]http://bugs.php.net/fix.php?id=40758&r=notenoughinfo[/url]
    Submitted twice: [url]http://bugs.php.net/fix.php?id=40758&r=submittedtwice[/url]
    register_globals: [url]http://bugs.php.net/fix.php?id=40758&r=globals[/url]
    PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=40758&r=php3[/url]
    Daylight Savings: [url]http://bugs.php.net/fix.php?id=40758&r=dst[/url]
    IIS Stability: [url]http://bugs.php.net/fix.php?id=40758&r=isapi[/url]
    Install GNU Sed: [url]http://bugs.php.net/fix.php?id=40758&r=gnused[/url]
    Floating point limitations: [url]http://bugs.php.net/fix.php?id=40758&r=float[/url]
    No Zend Extensions: [url]http://bugs.php.net/fix.php?id=40758&r=nozend[/url]
    MySQL Configuration Error: [url]http://bugs.php.net/fix.php?id=40758&r=mysqlcfg[/url]
    jostb2345 at yahoo dot com Guest

  2. Similar Questions and Discussions

    1. #26285 [Asn->Csd]: escapeshellarg uses wrong quotes on windows
      ID: 26285 Updated by: iliaa@php.net Reported By: jb at ez dot no -Status: Assigned +Status: Closed...
    2. #26285 [Opn->Asn]: escapeshellarg uses wrong quotes on windows
      ID: 26285 Updated by: iliaa@php.net Reported By: jb at ez dot no -Status: Open +Status: Assigned...
    3. #26285 [NEW]: escapeshellarg uses wrong quotes on windows
      From: jb at ez dot no Operating system: Windows PHP version: 4.3.3 PHP Bug Type: *General Issues Bug description: ...
    4. DirectX 9.0a fails Windows Logo test
      I followed directions from http://support.microsoft.com/default.aspx?scid=kb;EN- US;811263 I still have the error. dxwebsetup is able to...
    5. Automated test software - Windows telnet to SCO
      JWR wrote: How about "facetwin" software . I am told this will do that, but can't tell you first hard for about 6 weeks when I will be receiving...
  3. #2

    Default #40758 [Opn->Asn]: Test fcgi_is_fastcgi() is wrong on windows

    ID: 40758
    Updated by: [email]tony2001@php.net[/email]
    Reported By: jostb2345 at yahoo dot com
    -Status: Open
    +Status: Assigned
    -Bug Type: Reproducible crash
    +Bug Type: CGI related
    Operating System: Windows (all versions)
    PHP Version: 5.2.1
    -Assigned To:
    +Assigned To: dmitry


    Previous Comments:
    ------------------------------------------------------------------------

    [2007-03-08 13:45:33] jostb2345 at yahoo dot com

    Description:
    ------------
    On windows, php 5.2.0 and above the following code (written in
    pseudo-code) doesn't work anymore:

    socket = socket(AF_INET, ...);
    bind(socket, ...);
    listen(socket, ...);
    outputHandle=GetStdHandle(...);
    inputHandle=socket;
    CreateProcess(...,"php-cgi.exe", ..., IOHandles);

    The problem is that "is_fastcgi" is only set if the OutputHandle and
    ErrorHandle are invalid. If both are invalid, InputHandle is assumed to
    be a named pipe.

    The Unix version still uses the old (correct) code.

    To correct this problem either the old FCGI_isfcgi() should be used or
    the test must be dublicated. See procedures:

    int fcgi_init(void);
    int fcgi_is_fastcgi(void);


    Regards,
    Jost Boekemeier




    Reproduce code:
    ---------------
    See above. If necessary I can provide a test program.




    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40758&edit=1[/url]
    tony2001@php.net Guest

  4. #3

    Default #40758 [Asn->Fbk]: Test fcgi_is_fastcgi() is wrong on windows

    ID: 40758
    Updated by: [email]dmitry@php.net[/email]
    Reported By: jostb2345 at yahoo dot com
    -Status: Assigned
    +Status: Feedback
    Bug Type: CGI related
    Operating System: Windows (all versions)
    PHP Version: 5.2.1
    Assigned To: dmitry
    New Comment:

    I don't see any difference with old code. See OS_IsFcgi() and
    OS_LibInit().

    Also I don't understand for what reason some program passes stdout to
    PHP.


    Previous Comments:
    ------------------------------------------------------------------------

    [2007-03-08 13:45:33] jostb2345 at yahoo dot com

    Description:
    ------------
    On windows, php 5.2.0 and above the following code (written in
    pseudo-code) doesn't work anymore:

    socket = socket(AF_INET, ...);
    bind(socket, ...);
    listen(socket, ...);
    outputHandle=GetStdHandle(...);
    inputHandle=socket;
    CreateProcess(...,"php-cgi.exe", ..., IOHandles);

    The problem is that "is_fastcgi" is only set if the OutputHandle and
    ErrorHandle are invalid. If both are invalid, InputHandle is assumed to
    be a named pipe.

    The Unix version still uses the old (correct) code.

    To correct this problem either the old FCGI_isfcgi() should be used or
    the test must be dublicated. See procedures:

    int fcgi_init(void);
    int fcgi_is_fastcgi(void);


    Regards,
    Jost Boekemeier




    Reproduce code:
    ---------------
    See above. If necessary I can provide a test program.




    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40758&edit=1[/url]

    dmitry@php.net Guest

  5. #4

    Default #40758 [Com]: Test fcgi_is_fastcgi() is wrong on windows

    ID: 40758
    Comment by: jostb2345 at yahoo dot de
    Reported By: jostb2345 at yahoo dot com
    Status: Feedback
    Bug Type: CGI related
    Operating System: Windows (all versions)
    PHP Version: 5.2.1
    Assigned To: dmitry
    New Comment:

    # include <windows.h>
    # include <winsock2.h>
    # define close closesocket

    term() {
    printf("err:%d", (GetLastError()));
    exit(1);
    }

    struct sockaddr_in saddr;
    main() {
    SOCKET listen_handle;
    SOCKADDR_IN saServer;
    char *cmd = "php-cgi.exe";
    STARTUPINFO su_info;
    SECURITY_ATTRIBUTES sa = { 0 };
    WORD wVersionRequested = MAKEWORD(1,1);
    WSADATA wsaData;
    int n = WSAStartup(wVersionRequested, &wsaData);
    if (wsaData.wVersion != wVersionRequested) term();

    listen_handle = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

    saServer.sin_family = AF_INET;
    saServer.sin_addr.s_addr = INADDR_ANY;
    saServer.sin_port = htons(9667);

    n = bind(listen_handle, (LPSOCKADDR)&saServer, sizeof(struct
    sockaddr));
    if (n == SOCKET_ERROR) term();

    n = listen(listen_handle, 20);
    if (n == SOCKET_ERROR) term();


    ZeroMemory(&su_info, sizeof(STARTUPINFO));
    su_info.cb = sizeof(STARTUPINFO);
    su_info.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
    su_info.wShowWindow = SW_HIDE;
    su_info.hStdInput = listen_handle;
    su_info.hStdError = INVALID_HANDLE_VALUE;
    su_info.hStdOutput = INVALID_HANDLE_VALUE;
    SetHandleInformation(su_info.hStdInput, HANDLE_FLAG_INHERIT, TRUE);

    PROCESS_INFORMATION p;
    if(CreateProcess(NULL, cmd, NULL, NULL, 1, 0, NULL, NULL, &su_info,
    &p)) {
    CloseHandle(p.hThread); closesocket(listen_handle);
    } else {
    term();
    }
    if( WaitForSingleObject(p.hProcess, INFINITE) == WAIT_FAILED ){
    term();
    }
    WSACleanup();
    }


    Previous Comments:
    ------------------------------------------------------------------------

    [2007-03-09 13:36:15] [email]dmitry@php.net[/email]

    I don't see any difference with old code. See OS_IsFcgi() and
    OS_LibInit().

    Also I don't understand for what reason some program passes stdout to
    PHP.

    ------------------------------------------------------------------------

    [2007-03-08 13:45:33] jostb2345 at yahoo dot com

    Description:
    ------------
    On windows, php 5.2.0 and above the following code (written in
    pseudo-code) doesn't work anymore:

    socket = socket(AF_INET, ...);
    bind(socket, ...);
    listen(socket, ...);
    outputHandle=GetStdHandle(...);
    inputHandle=socket;
    CreateProcess(...,"php-cgi.exe", ..., IOHandles);

    The problem is that "is_fastcgi" is only set if the OutputHandle and
    ErrorHandle are invalid. If both are invalid, InputHandle is assumed to
    be a named pipe.

    The Unix version still uses the old (correct) code.

    To correct this problem either the old FCGI_isfcgi() should be used or
    the test must be dublicated. See procedures:

    int fcgi_init(void);
    int fcgi_is_fastcgi(void);


    Regards,
    Jost Boekemeier




    Reproduce code:
    ---------------
    See above. If necessary I can provide a test program.




    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40758&edit=1[/url]
    jostb2345 at yahoo dot de Guest

  6. #5

    Default #40758 [Fbk->Opn]: Test fcgi_is_fastcgi() is wrong on windows

    ID: 40758
    User updated by: jostb2345 at yahoo dot com
    Reported By: jostb2345 at yahoo dot com
    -Status: Feedback
    +Status: Open
    Bug Type: CGI related
    Operating System: Windows (all versions)
    PHP Version: 5.2.1
    Assigned To: dmitry
    New Comment:
    > I don't understand for what reason some program passes stdout to
    > PHP
    Because I thought you need to distinguish sockets from named pipes.
    I have attached code which crashes php since 5.2.0.


    Regards,
    Jost Boekemeier


    Previous Comments:
    ------------------------------------------------------------------------

    [2007-03-09 17:01:01] jostb2345 at yahoo dot de

    # include <windows.h>
    # include <winsock2.h>
    # define close closesocket

    term() {
    printf("err:%d", (GetLastError()));
    exit(1);
    }

    struct sockaddr_in saddr;
    main() {
    SOCKET listen_handle;
    SOCKADDR_IN saServer;
    char *cmd = "php-cgi.exe";
    STARTUPINFO su_info;
    SECURITY_ATTRIBUTES sa = { 0 };
    WORD wVersionRequested = MAKEWORD(1,1);
    WSADATA wsaData;
    int n = WSAStartup(wVersionRequested, &wsaData);
    if (wsaData.wVersion != wVersionRequested) term();

    listen_handle = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

    saServer.sin_family = AF_INET;
    saServer.sin_addr.s_addr = INADDR_ANY;
    saServer.sin_port = htons(9667);

    n = bind(listen_handle, (LPSOCKADDR)&saServer, sizeof(struct
    sockaddr));
    if (n == SOCKET_ERROR) term();

    n = listen(listen_handle, 20);
    if (n == SOCKET_ERROR) term();


    ZeroMemory(&su_info, sizeof(STARTUPINFO));
    su_info.cb = sizeof(STARTUPINFO);
    su_info.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
    su_info.wShowWindow = SW_HIDE;
    su_info.hStdInput = listen_handle;
    su_info.hStdError = INVALID_HANDLE_VALUE;
    su_info.hStdOutput = INVALID_HANDLE_VALUE;
    SetHandleInformation(su_info.hStdInput, HANDLE_FLAG_INHERIT, TRUE);

    PROCESS_INFORMATION p;
    if(CreateProcess(NULL, cmd, NULL, NULL, 1, 0, NULL, NULL, &su_info,
    &p)) {
    CloseHandle(p.hThread); closesocket(listen_handle);
    } else {
    term();
    }
    if( WaitForSingleObject(p.hProcess, INFINITE) == WAIT_FAILED ){
    term();
    }
    WSACleanup();
    }

    ------------------------------------------------------------------------

    [2007-03-09 13:36:15] [email]dmitry@php.net[/email]

    I don't see any difference with old code. See OS_IsFcgi() and
    OS_LibInit().

    Also I don't understand for what reason some program passes stdout to
    PHP.

    ------------------------------------------------------------------------

    [2007-03-08 13:45:33] jostb2345 at yahoo dot com

    Description:
    ------------
    On windows, php 5.2.0 and above the following code (written in
    pseudo-code) doesn't work anymore:

    socket = socket(AF_INET, ...);
    bind(socket, ...);
    listen(socket, ...);
    outputHandle=GetStdHandle(...);
    inputHandle=socket;
    CreateProcess(...,"php-cgi.exe", ..., IOHandles);

    The problem is that "is_fastcgi" is only set if the OutputHandle and
    ErrorHandle are invalid. If both are invalid, InputHandle is assumed to
    be a named pipe.

    The Unix version still uses the old (correct) code.

    To correct this problem either the old FCGI_isfcgi() should be used or
    the test must be dublicated. See procedures:

    int fcgi_init(void);
    int fcgi_is_fastcgi(void);


    Regards,
    Jost Boekemeier




    Reproduce code:
    ---------------
    See above. If necessary I can provide a test program.




    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40758&edit=1[/url]
    jostb2345 at yahoo dot com Guest

  7. #6

    Default #40758 [Opn->Asn]: Test fcgi_is_fastcgi() is wrong on windows

    ID: 40758
    Updated by: [email]tony2001@php.net[/email]
    Reported By: jostb2345 at yahoo dot com
    -Status: Open
    +Status: Assigned
    Bug Type: CGI related
    Operating System: Windows (all versions)
    PHP Version: 5.2.1
    Assigned To: dmitry


    Previous Comments:
    ------------------------------------------------------------------------

    [2007-03-09 17:06:35] jostb2345 at yahoo dot com
    > I don't understand for what reason some program passes stdout to
    > PHP
    Because I thought you need to distinguish sockets from named pipes.
    I have attached code which crashes php since 5.2.0.


    Regards,
    Jost Boekemeier

    ------------------------------------------------------------------------

    [2007-03-09 17:01:01] jostb2345 at yahoo dot de

    # include <windows.h>
    # include <winsock2.h>
    # define close closesocket

    term() {
    printf("err:%d", (GetLastError()));
    exit(1);
    }

    struct sockaddr_in saddr;
    main() {
    SOCKET listen_handle;
    SOCKADDR_IN saServer;
    char *cmd = "php-cgi.exe";
    STARTUPINFO su_info;
    SECURITY_ATTRIBUTES sa = { 0 };
    WORD wVersionRequested = MAKEWORD(1,1);
    WSADATA wsaData;
    int n = WSAStartup(wVersionRequested, &wsaData);
    if (wsaData.wVersion != wVersionRequested) term();

    listen_handle = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

    saServer.sin_family = AF_INET;
    saServer.sin_addr.s_addr = INADDR_ANY;
    saServer.sin_port = htons(9667);

    n = bind(listen_handle, (LPSOCKADDR)&saServer, sizeof(struct
    sockaddr));
    if (n == SOCKET_ERROR) term();

    n = listen(listen_handle, 20);
    if (n == SOCKET_ERROR) term();


    ZeroMemory(&su_info, sizeof(STARTUPINFO));
    su_info.cb = sizeof(STARTUPINFO);
    su_info.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
    su_info.wShowWindow = SW_HIDE;
    su_info.hStdInput = listen_handle;
    su_info.hStdError = INVALID_HANDLE_VALUE;
    su_info.hStdOutput = INVALID_HANDLE_VALUE;
    SetHandleInformation(su_info.hStdInput, HANDLE_FLAG_INHERIT, TRUE);

    PROCESS_INFORMATION p;
    if(CreateProcess(NULL, cmd, NULL, NULL, 1, 0, NULL, NULL, &su_info,
    &p)) {
    CloseHandle(p.hThread); closesocket(listen_handle);
    } else {
    term();
    }
    if( WaitForSingleObject(p.hProcess, INFINITE) == WAIT_FAILED ){
    term();
    }
    WSACleanup();
    }

    ------------------------------------------------------------------------

    [2007-03-09 13:36:15] [email]dmitry@php.net[/email]

    I don't see any difference with old code. See OS_IsFcgi() and
    OS_LibInit().

    Also I don't understand for what reason some program passes stdout to
    PHP.

    ------------------------------------------------------------------------

    [2007-03-08 13:45:33] jostb2345 at yahoo dot com

    Description:
    ------------
    On windows, php 5.2.0 and above the following code (written in
    pseudo-code) doesn't work anymore:

    socket = socket(AF_INET, ...);
    bind(socket, ...);
    listen(socket, ...);
    outputHandle=GetStdHandle(...);
    inputHandle=socket;
    CreateProcess(...,"php-cgi.exe", ..., IOHandles);

    The problem is that "is_fastcgi" is only set if the OutputHandle and
    ErrorHandle are invalid. If both are invalid, InputHandle is assumed to
    be a named pipe.

    The Unix version still uses the old (correct) code.

    To correct this problem either the old FCGI_isfcgi() should be used or
    the test must be dublicated. See procedures:

    int fcgi_init(void);
    int fcgi_is_fastcgi(void);


    Regards,
    Jost Boekemeier




    Reproduce code:
    ---------------
    See above. If necessary I can provide a test program.




    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40758&edit=1[/url]
    tony2001@php.net Guest

  8. #7

    Default #40758 [Asn->Fbk]: Test fcgi_is_fastcgi() is wrong on windows

    ID: 40758
    Updated by: [email]dmitry@php.net[/email]
    Reported By: jostb2345 at yahoo dot com
    -Status: Assigned
    +Status: Feedback
    Bug Type: CGI related
    Operating System: Windows (all versions)
    PHP Version: 5.2.1
    Assigned To: dmitry
    New Comment:

    yes. PHP expects pipe but not a socket.

    In C you may even try to pass window HANDLE :)

    May be older PHP versions were able to support sockets on win32, but I
    have never seen any FastCGI plugin implmentation that passes sockets.
    Also I don't see any sockets advantages (only disadvantages).



    Previous Comments:
    ------------------------------------------------------------------------

    [2007-03-09 17:06:35] jostb2345 at yahoo dot com
    > I don't understand for what reason some program passes stdout to
    > PHP
    Because I thought you need to distinguish sockets from named pipes.
    I have attached code which crashes php since 5.2.0.


    Regards,
    Jost Boekemeier

    ------------------------------------------------------------------------

    [2007-03-09 17:01:01] jostb2345 at yahoo dot de

    # include <windows.h>
    # include <winsock2.h>
    # define close closesocket

    term() {
    printf("err:%d", (GetLastError()));
    exit(1);
    }

    struct sockaddr_in saddr;
    main() {
    SOCKET listen_handle;
    SOCKADDR_IN saServer;
    char *cmd = "php-cgi.exe";
    STARTUPINFO su_info;
    SECURITY_ATTRIBUTES sa = { 0 };
    WORD wVersionRequested = MAKEWORD(1,1);
    WSADATA wsaData;
    int n = WSAStartup(wVersionRequested, &wsaData);
    if (wsaData.wVersion != wVersionRequested) term();

    listen_handle = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

    saServer.sin_family = AF_INET;
    saServer.sin_addr.s_addr = INADDR_ANY;
    saServer.sin_port = htons(9667);

    n = bind(listen_handle, (LPSOCKADDR)&saServer, sizeof(struct
    sockaddr));
    if (n == SOCKET_ERROR) term();

    n = listen(listen_handle, 20);
    if (n == SOCKET_ERROR) term();


    ZeroMemory(&su_info, sizeof(STARTUPINFO));
    su_info.cb = sizeof(STARTUPINFO);
    su_info.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
    su_info.wShowWindow = SW_HIDE;
    su_info.hStdInput = listen_handle;
    su_info.hStdError = INVALID_HANDLE_VALUE;
    su_info.hStdOutput = INVALID_HANDLE_VALUE;
    SetHandleInformation(su_info.hStdInput, HANDLE_FLAG_INHERIT, TRUE);

    PROCESS_INFORMATION p;
    if(CreateProcess(NULL, cmd, NULL, NULL, 1, 0, NULL, NULL, &su_info,
    &p)) {
    CloseHandle(p.hThread); closesocket(listen_handle);
    } else {
    term();
    }
    if( WaitForSingleObject(p.hProcess, INFINITE) == WAIT_FAILED ){
    term();
    }
    WSACleanup();
    }

    ------------------------------------------------------------------------

    [2007-03-09 13:36:15] [email]dmitry@php.net[/email]

    I don't see any difference with old code. See OS_IsFcgi() and
    OS_LibInit().

    Also I don't understand for what reason some program passes stdout to
    PHP.

    ------------------------------------------------------------------------

    [2007-03-08 13:45:33] jostb2345 at yahoo dot com

    Description:
    ------------
    On windows, php 5.2.0 and above the following code (written in
    pseudo-code) doesn't work anymore:

    socket = socket(AF_INET, ...);
    bind(socket, ...);
    listen(socket, ...);
    outputHandle=GetStdHandle(...);
    inputHandle=socket;
    CreateProcess(...,"php-cgi.exe", ..., IOHandles);

    The problem is that "is_fastcgi" is only set if the OutputHandle and
    ErrorHandle are invalid. If both are invalid, InputHandle is assumed to
    be a named pipe.

    The Unix version still uses the old (correct) code.

    To correct this problem either the old FCGI_isfcgi() should be used or
    the test must be dublicated. See procedures:

    int fcgi_init(void);
    int fcgi_is_fastcgi(void);


    Regards,
    Jost Boekemeier




    Reproduce code:
    ---------------
    See above. If necessary I can provide a test program.




    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40758&edit=1[/url]
    dmitry@php.net Guest

  9. #8

    Default #40758 [Fbk->Opn]: Test fcgi_is_fastcgi() is wrong on windows

    ID: 40758
    User updated by: jostb2345 at yahoo dot com
    Reported By: jostb2345 at yahoo dot com
    -Status: Feedback
    +Status: Open
    Bug Type: CGI related
    Operating System: Windows (all versions)
    PHP Version: 5.2.1
    Assigned To: dmitry
    New Comment:
    > May be older PHP versions were able to support sockets on win32, but
    I
    > have never seen any FastCGI plugin implmentation that passes
    sockets.

    PHPIntKitForWindows.zip

    => [url]http://www.alphaworks.ibm.com/tech/phpintwasce/download[/url]

    > Also I don't see any sockets advantages (only disadvantages).
    I don't think named pipes work on all operating systems. Furthermore
    Java supports only TCP socket communication (well, it is possible to
    access Windows and Unix named pipes from Java. But one has to implement
    it twice. RandomAccessFile on Windows, a pair of normal Files on Unix).


    To be practical -- and for backward compatibility -- we need a working
    TCP socket implementation on both operating systems. tcp sockets worked
    in PHP versions < 5.2.0 and I don't see a good reason to drop this.


    Regards,
    Jost Boekemeier


    Previous Comments:
    ------------------------------------------------------------------------

    [2007-03-12 17:21:32] [email]dmitry@php.net[/email]

    yes. PHP expects pipe but not a socket.

    In C you may even try to pass window HANDLE :)

    May be older PHP versions were able to support sockets on win32, but I
    have never seen any FastCGI plugin implmentation that passes sockets.
    Also I don't see any sockets advantages (only disadvantages).


    ------------------------------------------------------------------------

    [2007-03-09 17:06:35] jostb2345 at yahoo dot com
    > I don't understand for what reason some program passes stdout to
    > PHP
    Because I thought you need to distinguish sockets from named pipes.
    I have attached code which crashes php since 5.2.0.


    Regards,
    Jost Boekemeier

    ------------------------------------------------------------------------

    [2007-03-09 17:01:01] jostb2345 at yahoo dot de

    # include <windows.h>
    # include <winsock2.h>
    # define close closesocket

    term() {
    printf("err:%d", (GetLastError()));
    exit(1);
    }

    struct sockaddr_in saddr;
    main() {
    SOCKET listen_handle;
    SOCKADDR_IN saServer;
    char *cmd = "php-cgi.exe";
    STARTUPINFO su_info;
    SECURITY_ATTRIBUTES sa = { 0 };
    WORD wVersionRequested = MAKEWORD(1,1);
    WSADATA wsaData;
    int n = WSAStartup(wVersionRequested, &wsaData);
    if (wsaData.wVersion != wVersionRequested) term();

    listen_handle = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

    saServer.sin_family = AF_INET;
    saServer.sin_addr.s_addr = INADDR_ANY;
    saServer.sin_port = htons(9667);

    n = bind(listen_handle, (LPSOCKADDR)&saServer, sizeof(struct
    sockaddr));
    if (n == SOCKET_ERROR) term();

    n = listen(listen_handle, 20);
    if (n == SOCKET_ERROR) term();


    ZeroMemory(&su_info, sizeof(STARTUPINFO));
    su_info.cb = sizeof(STARTUPINFO);
    su_info.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
    su_info.wShowWindow = SW_HIDE;
    su_info.hStdInput = listen_handle;
    su_info.hStdError = INVALID_HANDLE_VALUE;
    su_info.hStdOutput = INVALID_HANDLE_VALUE;
    SetHandleInformation(su_info.hStdInput, HANDLE_FLAG_INHERIT, TRUE);

    PROCESS_INFORMATION p;
    if(CreateProcess(NULL, cmd, NULL, NULL, 1, 0, NULL, NULL, &su_info,
    &p)) {
    CloseHandle(p.hThread); closesocket(listen_handle);
    } else {
    term();
    }
    if( WaitForSingleObject(p.hProcess, INFINITE) == WAIT_FAILED ){
    term();
    }
    WSACleanup();
    }

    ------------------------------------------------------------------------

    [2007-03-09 13:36:15] [email]dmitry@php.net[/email]

    I don't see any difference with old code. See OS_IsFcgi() and
    OS_LibInit().

    Also I don't understand for what reason some program passes stdout to
    PHP.

    ------------------------------------------------------------------------

    [2007-03-08 13:45:33] jostb2345 at yahoo dot com

    Description:
    ------------
    On windows, php 5.2.0 and above the following code (written in
    pseudo-code) doesn't work anymore:

    socket = socket(AF_INET, ...);
    bind(socket, ...);
    listen(socket, ...);
    outputHandle=GetStdHandle(...);
    inputHandle=socket;
    CreateProcess(...,"php-cgi.exe", ..., IOHandles);

    The problem is that "is_fastcgi" is only set if the OutputHandle and
    ErrorHandle are invalid. If both are invalid, InputHandle is assumed to
    be a named pipe.

    The Unix version still uses the old (correct) code.

    To correct this problem either the old FCGI_isfcgi() should be used or
    the test must be dublicated. See procedures:

    int fcgi_init(void);
    int fcgi_is_fastcgi(void);


    Regards,
    Jost Boekemeier




    Reproduce code:
    ---------------
    See above. If necessary I can provide a test program.




    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40758&edit=1[/url]
    jostb2345 at yahoo dot com Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139