php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40594 Blocking socket functions cause Apache freeze
Submitted: 2007-02-22 16:39 UTC Modified: 2007-02-22 22:04 UTC
Votes:2
Avg. Score:3.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: karldray at interchange dot ubc dot ca Assigned:
Status: Not a bug Package: Sockets related
PHP Version: 5.2.1 OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: karldray at interchange dot ubc dot ca
New email:
PHP Version: OS:

 

 [2007-02-22 16:39 UTC] 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).

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-02-22 21:53 UTC] 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 21:57 UTC] karldray at interchange dot ubc dot ca
I'm resubmitting this bug as a performance problem. (See previous comment.)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 14:01:31 2024 UTC