php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41875 io_add_watch can't detect HUPs
Submitted: 2007-07-02 19:04 UTC Modified: 2007-07-19 16:39 UTC
From: sebastianmarconi at gmail dot com Assigned:
Status: Not a bug Package: PHP-GTK related
PHP Version: 5.2.3 OS: Windows XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: sebastianmarconi at gmail dot com
New email:
PHP Version: OS:

 

 [2007-07-02 19:04 UTC] sebastianmarconi at gmail dot com
Description:
------------
It seems that Gtk::io_add_watch
can't detect HUP conditions using
beta Windows binary with Gtk+ 2.10.

In some cases the only workaround that I've found is to look the process status info [1] in the STDOUT callback (sometimes it sends IO_IN signals constantly), but randomly losses some information.


[1]
<?php

$status = proc_get_status($proc_id);
if (! $status['running']) {
	$this->io_hup($pipe);
}	

?>

Reproduce code:
---------------
<?php

function out($pipe) {
       echo "STDOUT\n";
       echo stream_get_contents($pipe);
}

function hup($pipe){
       echo "HUP\n";
       Gtk::main_quit();
       return false;
}


$pipes = null;
$descriptor = array(
       0 => array("pipe", "r"),  // stdin
       1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
       2 => array("pipe", "w")   // stderr
);
$cmd = 'dir';
$p = proc_open($cmd, $descriptor, $pipes);
Gtk::io_add_watch($pipes[1],Gtk::IO_IN, 'out');
Gtk::io_add_watch($pipes[1],Gtk::IO_HUP, 'hup');

Gtk::main();
echo "EXIT\n";
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);

?>

Expected result:
----------------
STDOUT
[Dir contents]
HUP
EXIT

Actual result:
--------------
STDOUT
[The script hangs]

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-18 19:02 UTC] bob at kateos dot org
works as expected on Linux.
 [2007-07-18 20:17 UTC] auroraeosrose@php.net
You need to add code to detect HUP | IN - hup is never being called separately so the second watch is never being fired

<?php

function out($pipe) {
       echo "STDOUT\n";
       echo stream_get_contents($pipe);
}

function hupin($pipe){
       echo "STDOUT\n";
       echo stream_get_contents($pipe);
       echo "HUP\n";
       Gtk::main_quit();
       return false;
}

function hup($pipe){
       echo "HUP\n";
       Gtk::main_quit();
       return false;
}

$pipes = null;
$descriptor = array(
       0 => array("pipe", "r"),  // stdin
       1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
       2 => array("pipe", "w")   // stderr
);
$cmd = 'dir';
$p = proc_open($cmd, $descriptor, $pipes);
Gtk::io_add_watch($pipes[1],GTK::IO_IN, 'out');
Gtk::io_add_watch($pipes[1],GTK::IO_HUP, 'hup');
Gtk::io_add_watch($pipes[1],GTK::IO_HUP | GTK::IO_IN, 'hupin');

Gtk::main();
echo "EXIT\n";
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
?>


 [2007-07-19 16:39 UTC] sebastianmarconi at gmail dot com
@auroraeosrose
Using Windows binary with Gtk+ 2.10 with GTK::IO_HUP | GTK::IO_IN the script doesn't hang anymore but shows the content partially. For example sometimes only the first lines, others only the last, and regularly there's no output at all.

If you use the second argument of the watch :

function hupin($pipe, $condition)

Only IO_IN (integer 1) is fired, in few cases both IO_IN| IO_HUP (integer 17). In previous version (2.0.0 alpha) IO_HUP worked correctly.

This only is a toy example, but my main application uses this behavior avoiding the 'busy-wait' effect in several long running tasks (wrapping svn commands for example), and currently it's loosing functionality in Windows.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 06:01:29 2024 UTC