17 feb. 2010 : PHP-GTK Application descriptions can now be submitted in Brazilian Portuguese too. Thanks Bruno Bandeira !.

German and Italian still missing: who will contribute the translated categories for these languages ? Contact the team to offer your translations !

PHP-GTK + pcntl_fork()

Hi. Code:

<?php
$window
= new GtkWindow;
$window->set_size_request(200, 100);
$window->connect_simple('destroy', 'Gtk::main_quit');

$pid = pcntl_fork();
if (
$pid == -1)
    exit(
"Error\n");
else if (
$pid)
    echo
"parent\n";
else
    echo
"child\n";

$window->show_all();
Gtk::main();
?>

Run: the program crashes and displays an error:

parent
child
The program 'index.php' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadIDChoice (invalid resource ID chosen for this connection)'.
  (Details: serial 175 error_code 14 request_code 1 minor_code 0)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the --sync command line
   option to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)
index.php: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.0.

to use pcntl fork you need

to use pcntl fork you need to keep all the gtk stuff in the parent. like this
<?php
$pid
= pcntl_fork();
if (
$pid == -1){
    exit(
"Error\n");
}else if (
$pid){
    echo
"parent\n";
   
$window = new GtkWindow;
   
$window->set_size_request(200, 100);
   
$window->connect_simple('destroy', 'Gtk::main_quit');
   
$window->show_all();
   
Gtk::main();
}else{
    echo
"child\n";
}
?>
do not call any gtk stuff from the child process or your app will crash. You can communicate with the two with a unix socket hope this helps

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.