#40594 [NEW]: Blocking socket functions cause Apache freeze

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

  1. #1

    Default #40594 [NEW]: Blocking socket functions cause Apache freeze

    From: karldray at interchange dot ubc dot ca
    Operating system: Windows XP
    PHP version: 5.2.1
    PHP Bug Type: Sockets related
    Bug description: Blocking socket functions cause Apache freeze

    Description:
    ------------
    I have a PHP page that opens a UDP socket and listens for data (blocking
    on socket_recvfrom). When the socket recieves a packet, the script echoes
    a message and finishes. This works fine, but when two instances of this
    page are running (both blocking on socket_recvfrom), Apache (2.2.4) stops
    responding to any new requests (even for non-php pages) until one of them
    gets unblocked. The same problem occurs with other blocking socket
    functions (such as socket_accept and socket_read with TCP sockets).

    Reproduction instructions:
    1. open a browser window to udp_recv.php?port=11111. it sits there
    "loading" since PHP is waiting for socket data.
    2. open another browser window to udp_recv.php?port=22222.
    3 (the problem). open another browser window and point it to index.html or
    any other url on the server. it just sits there "loading".
    4. in a command prompt, type "perl udp_send.pl 11111" to send 'hello' to
    the first php script's udp socket, causing it to finish. Suddenly, the
    third request completes.

    Reproduce code:
    ---------------
    udp_recv.php:

    <?php
    $listener = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
    socket_bind($listener, gethostbyname('localhost'), $_GET['port']) or
    exit('error on bind');
    $len = socket_recvfrom($listener, $data, 2048, 0, $host, $port);
    echo "$len bytes recieved from $host:$port: $data\n";
    ?>

    udp_send.pl:

    use strict; use Socket;
    socket(SOCKET, PF_INET, SOCK_DGRAM, getprotobyname('udp')) or die "socket:
    $!";
    send(SOCKET, 'hello', 0, sockaddr_in(shift, inet_aton('localhost'))) or
    die "send: $!";


    Expected result:
    ----------------
    I expect Apache to continue to accept and handle new web page requests
    while the two PHP pages are blocking on socket functions.

    Actual result:
    --------------
    Once there are two PHP pages blocking on socket functions, all subsequent
    requests (even for non-php URIs) appear as "loading" in the browser until
    one of the PHP scripts unblocks.

    Note: If the third request is for a PHP page containing an error_log() at
    the very beginning, then the logfile output is not generated as long as
    the first two pages are blocking (suggesting that Apache isn't getting
    around to starting PHP during this time).

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

  2. Similar Questions and Discussions

    1. #38982 [NEW]: No SSL-socket functions in CLI
      From: admin at denic-294 dot de Operating system: Debian diffrent releases PHP version: 4.4.4 PHP Bug Type: OpenSSL related...
    2. #40596 [NEW]: Running two PHP scripts causes Apache freeze
      From: karldray at interchange dot ubc dot ca Operating system: Windows XP SP2 PHP version: 5.2.1 PHP Bug Type: Apache2...
    3. #28136 [Com]: Problems with connection of a non blocking socket
      ID: 28136 Comment by: fakeman at i dot ua Reported By: daniele-dll at yahoo dot it Status: No Feedback Bug...
    4. Non-blocking Filehandles for Socket I/O
      How do you intend to access the socket ? Will you just programmatically poll until read() returns data, or will you use select() ? If the latter,...
    5. Will Thread blocking in read() leads to process blocking?
      Hi! Yes, the outcome depends on the threads implementation. However, it is incorrect to believe that a POSIX conformant implementation won't...
  3. #2

    Default #40594 [Opn]: Blocking socket functions cause Apache freeze

    ID: 40594
    User updated by: karldray at interchange dot ubc dot ca
    Reported By: karldray at interchange dot ubc dot ca
    Status: Open
    Bug Type: Sockets related
    Operating System: Windows XP
    PHP Version: 5.2.1
    New Comment:

    This turns out not to be specific to sockets or even to blocking
    functions! I just realized that if I replace udp_recv.php with a
    one-line script like
    sleep(10);
    or something like
    for($i=0;$i<100000000;$i++);
    then the same problem occurs: while two of them are running, apache
    won't handle any new requests.


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

    [2007-02-22 16:39:34] karldray at interchange dot ubc dot ca

    Description:
    ------------
    I have a PHP page that opens a UDP socket and listens for data
    (blocking on socket_recvfrom). When the socket recieves a packet, the
    script echoes a message and finishes. This works fine, but when two
    instances of this page are running (both blocking on socket_recvfrom),
    Apache (2.2.4) stops responding to any new requests (even for non-php
    pages) until one of them gets unblocked. The same problem occurs with
    other blocking socket functions (such as socket_accept and socket_read
    with TCP sockets).

    Reproduction instructions:
    1. open a browser window to udp_recv.php?port=11111. it sits there
    "loading" since PHP is waiting for socket data.
    2. open another browser window to udp_recv.php?port=22222.
    3 (the problem). open another browser window and point it to index.html
    or any other url on the server. it just sits there "loading".
    4. in a command prompt, type "perl udp_send.pl 11111" to send 'hello'
    to the first php script's udp socket, causing it to finish. Suddenly,
    the third request completes.

    Reproduce code:
    ---------------
    udp_recv.php:

    <?php
    $listener = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
    socket_bind($listener, gethostbyname('localhost'), $_GET['port']) or
    exit('error on bind');
    $len = socket_recvfrom($listener, $data, 2048, 0, $host, $port);
    echo "$len bytes recieved from $host:$port: $data\n";
    ?>

    udp_send.pl:

    use strict; use Socket;
    socket(SOCKET, PF_INET, SOCK_DGRAM, getprotobyname('udp')) or die
    "socket: $!";
    send(SOCKET, 'hello', 0, sockaddr_in(shift, inet_aton('localhost'))) or
    die "send: $!";


    Expected result:
    ----------------
    I expect Apache to continue to accept and handle new web page requests
    while the two PHP pages are blocking on socket functions.

    Actual result:
    --------------
    Once there are two PHP pages blocking on socket functions, all
    subsequent requests (even for non-php URIs) appear as "loading" in the
    browser until one of the PHP scripts unblocks.

    Note: If the third request is for a PHP page containing an error_log()
    at the very beginning, then the logfile output is not generated as long
    as the first two pages are blocking (suggesting that Apache isn't
    getting around to starting PHP during this time).


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


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40594&edit=1[/url]
    karldray at interchange dot ubc dot ca Guest

  4. #3

    Default #40594 [Opn->Csd]: Blocking socket functions cause Apache freeze

    ID: 40594
    User updated by: karldray at interchange dot ubc dot ca
    Reported By: karldray at interchange dot ubc dot ca
    -Status: Open
    +Status: Closed
    Bug Type: Sockets related
    Operating System: Windows XP
    PHP Version: 5.2.1
    New Comment:

    I'm resubmitting this bug as a performance problem. (See previous
    comment.)


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

    [2007-02-22 21:53:47] karldray at interchange dot ubc dot ca

    This turns out not to be specific to sockets or even to blocking
    functions! I just realized that if I replace udp_recv.php with a
    one-line script like
    sleep(10);
    or something like
    for($i=0;$i<100000000;$i++);
    then the same problem occurs: while two of them are running, apache
    won't handle any new requests.

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

    [2007-02-22 16:39:34] karldray at interchange dot ubc dot ca

    Description:
    ------------
    I have a PHP page that opens a UDP socket and listens for data
    (blocking on socket_recvfrom). When the socket recieves a packet, the
    script echoes a message and finishes. This works fine, but when two
    instances of this page are running (both blocking on socket_recvfrom),
    Apache (2.2.4) stops responding to any new requests (even for non-php
    pages) until one of them gets unblocked. The same problem occurs with
    other blocking socket functions (such as socket_accept and socket_read
    with TCP sockets).

    Reproduction instructions:
    1. open a browser window to udp_recv.php?port=11111. it sits there
    "loading" since PHP is waiting for socket data.
    2. open another browser window to udp_recv.php?port=22222.
    3 (the problem). open another browser window and point it to index.html
    or any other url on the server. it just sits there "loading".
    4. in a command prompt, type "perl udp_send.pl 11111" to send 'hello'
    to the first php script's udp socket, causing it to finish. Suddenly,
    the third request completes.

    Reproduce code:
    ---------------
    udp_recv.php:

    <?php
    $listener = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
    socket_bind($listener, gethostbyname('localhost'), $_GET['port']) or
    exit('error on bind');
    $len = socket_recvfrom($listener, $data, 2048, 0, $host, $port);
    echo "$len bytes recieved from $host:$port: $data\n";
    ?>

    udp_send.pl:

    use strict; use Socket;
    socket(SOCKET, PF_INET, SOCK_DGRAM, getprotobyname('udp')) or die
    "socket: $!";
    send(SOCKET, 'hello', 0, sockaddr_in(shift, inet_aton('localhost'))) or
    die "send: $!";


    Expected result:
    ----------------
    I expect Apache to continue to accept and handle new web page requests
    while the two PHP pages are blocking on socket functions.

    Actual result:
    --------------
    Once there are two PHP pages blocking on socket functions, all
    subsequent requests (even for non-php URIs) appear as "loading" in the
    browser until one of the PHP scripts unblocks.

    Note: If the third request is for a PHP page containing an error_log()
    at the very beginning, then the logfile output is not generated as long
    as the first two pages are blocking (suggesting that Apache isn't
    getting around to starting PHP during this time).


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


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40594&edit=1[/url]
    karldray at interchange dot ubc dot ca Guest

  5. #4

    Default #40594 [Csd->Bgs]: Blocking socket functions cause Apache freeze

    ID: 40594
    Updated by: [email]tony2001@php.net[/email]
    Reported By: karldray at interchange dot ubc dot ca
    -Status: Closed
    +Status: Bogus
    Bug Type: Sockets related
    Operating System: Windows XP
    PHP Version: 5.2.1


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

    [2007-02-22 21:57:02] karldray at interchange dot ubc dot ca

    I'm resubmitting this bug as a performance problem. (See previous
    comment.)

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

    [2007-02-22 21:53:47] karldray at interchange dot ubc dot ca

    This turns out not to be specific to sockets or even to blocking
    functions! I just realized that if I replace udp_recv.php with a
    one-line script like
    sleep(10);
    or something like
    for($i=0;$i<100000000;$i++);
    then the same problem occurs: while two of them are running, apache
    won't handle any new requests.

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

    [2007-02-22 16:39:34] karldray at interchange dot ubc dot ca

    Description:
    ------------
    I have a PHP page that opens a UDP socket and listens for data
    (blocking on socket_recvfrom). When the socket recieves a packet, the
    script echoes a message and finishes. This works fine, but when two
    instances of this page are running (both blocking on socket_recvfrom),
    Apache (2.2.4) stops responding to any new requests (even for non-php
    pages) until one of them gets unblocked. The same problem occurs with
    other blocking socket functions (such as socket_accept and socket_read
    with TCP sockets).

    Reproduction instructions:
    1. open a browser window to udp_recv.php?port=11111. it sits there
    "loading" since PHP is waiting for socket data.
    2. open another browser window to udp_recv.php?port=22222.
    3 (the problem). open another browser window and point it to index.html
    or any other url on the server. it just sits there "loading".
    4. in a command prompt, type "perl udp_send.pl 11111" to send 'hello'
    to the first php script's udp socket, causing it to finish. Suddenly,
    the third request completes.

    Reproduce code:
    ---------------
    udp_recv.php:

    <?php
    $listener = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
    socket_bind($listener, gethostbyname('localhost'), $_GET['port']) or
    exit('error on bind');
    $len = socket_recvfrom($listener, $data, 2048, 0, $host, $port);
    echo "$len bytes recieved from $host:$port: $data\n";
    ?>

    udp_send.pl:

    use strict; use Socket;
    socket(SOCKET, PF_INET, SOCK_DGRAM, getprotobyname('udp')) or die
    "socket: $!";
    send(SOCKET, 'hello', 0, sockaddr_in(shift, inet_aton('localhost'))) or
    die "send: $!";


    Expected result:
    ----------------
    I expect Apache to continue to accept and handle new web page requests
    while the two PHP pages are blocking on socket functions.

    Actual result:
    --------------
    Once there are two PHP pages blocking on socket functions, all
    subsequent requests (even for non-php URIs) appear as "loading" in the
    browser until one of the PHP scripts unblocks.

    Note: If the third request is for a PHP page containing an error_log()
    at the very beginning, then the logfile output is not generated as long
    as the first two pages are blocking (suggesting that Apache isn't
    getting around to starting PHP during this time).


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


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40594&edit=1[/url]
    tony2001@php.net 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