Article

Run PHP-GTK and PHP-Apache on Win32

Page: 1 2

The Test

Save the following as -f c:\gtk\samples\simple.php (and don't worry about what's in the code just yet).

<?  
dl('php_gtk.'.(strstr(PHP_OS, 'WIN') ? 'dll' : 'so'));  
 
function delete_event(){  
   return false;  
   }  
 
function shutdown(){  
   print("Shutting down...  
");  
   gtk::main_quit();  
   }  
     
function hello(){  
   global    $window;  
   print 'Hello World! "  
."';  
   $window->destroy();  
}  
 
$window = &new GtkWindow();  
$window->connect('destroy', 'shutdown');  
$window->connect('delete-event', 'delete_event');  
$window->set_border_width(10);  
 
$button = &new GtkButton('Hello World!');  
$button->connect('clicked', 'hello');  
$window->add($button);  
 
$window->show_all();  
Gtk::main();  
?>  

To run that script we need to use what can only be described as some inelegant command line scrawlings. To this end, I normally write a batch file -- it's far less frustrating than making typos in Windows' woeful command window.

There are 3 sections to worry about in our command line:

  1. the path to PHP

  2. the path to your php.ini and

  3. the path to your script

cd c:\gtk\php4\php.exe -q

This command tells Windows where to find PHP.exe if it's not in your PATH (and if it is in your PATH, it's probably the wrong php.exe). The -q switch suppresses any HTTP headers that PHP might otherwise create.

Trying to use your existing php.ini in your system directory can cause many an error, depending on how much you have modified it (though, for a start, you can expect all the include and extension paths to be wrong).

The -c switch lets us specify an alternate php.ini to the defaults, which are c:\windows(WINNT)\php.ini or c:\PHP\php.ini or ? \your_path\php\php.ini

-c c:\gtk\php4\php.ini

Now: identifying the path to the script that we want to run. The -f switch tells PHP that this is a file and not some other argument. You can actually live without it in most cases, but it's hardly a hassle to use it!

-f c:\gtk\samples\simple.php

All this comes together as the ungainly but effective:

cd c:\gtk\php4\php.exe -q -c c:\gtk\php4\php.ini -f c:\gtk\samples\simple.php

You can see why batch files are so useful (masochists can type the above at a command prompt if they wish). I'd save the above as c:\gtk\simple.bat (or anywhere on your machine) and click away. Voila ! an x-platform window without a snake in site.

To sum up, get your gtk directory to look like this: C:\gtk\php4

  • gdk-1.3.dll
  • glib-1.3.dll
  • gmodule-1.3.dll
  • gnu-intl.dll
  • gtk-1.3.dll
  • iconv-1.3.dll
  • libglade-0.14.dll
  • libxml.dll
  • php.exe
  • php.ini
  • php_gtk.dll
  • php_gtk_libglade.dll
  • php_gtk_sqpane.dll
  • php_win.exe
  • php4ts.dll

And a testing directory C:\gtk\samples

  • simple.php (among others)

That's the basics -- and all you actually need to run PHP-GTK!

Notes and Resources

php_win.exe?

You probably noticed the php_win.exe. As far as I can tell, the php_win.exe is only different in that it allows your PHP-GTK scripts to run without the DOS window that will otherwise pop up whenever you run a PHP-GTK application. This is great for presentation, but note that if you echo to stdout, then the app will crash, so direct any output to file if you want to debug with php_win.exe.

Also, it appears that php_win.exe looks first for extensions etc. in C:\PHP. It will use those if it finds them, as opposed to the ones in \system32\ (this is only my observation).

Extensions

Your c:\gtk\PHP4\php.ini should have no extensions enabled. We dl() the gtk module, and you will have to test individual extensions on a trial and error basis (MySQL/FTP etc are all available anyway).

Conclusion...

Now that you're up and running, you'll be wondering what's next. I'd suggest you download the PHP-GTK manual from gtk.php.net and browse the site -- there are some useful snippets in the manual, and a few links to apps and other resources that are a good starting point for world domination via PHP & PHP-GTK! Enjoy!

If you liked this article, share the love:
Print-Friendly Version Suggest an Article

Sponsored Links

Rate This Article

  • 1
    Poor
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
    Great

Comment on This Article

Have something to say?

Post A Comment

You need to be a member of the SitePoint Forums to comment on this post. Sign Up

Already a member? Post using your SitePoint Forums account: