picture of Iman Suyoto
One day, I found a site about Ming, a SWF output library and PHP module. Somehow, it attracted me, and gave me a driving force to try it immediately. I tried to read quickly to find things I'd be able to download. I downloaded the source code, the examples, and the precompiled PHP module. When I don't have extra time, sometimes I think, "why compile it myself if someone else has compiled it for me?" Therefore, I fetched the compressed file, uncompressed it into a server running Debian GNU/Linux 2.2.
According to the installation howto, what I'd need to do was just download the PHP module and put the uncompressed php_ming.so to PHP module directory. PHP module directory? Where is it? Aha, simply run php-config --extension-dir. "Piece of cake", I thought.
The last step was adding extension=php_ming.so. I tried the sample code (you'll find it later in this article) -- it didn't work. My intuition told me that it might be because I was using Debian along with the stable packages I apt-got (... err... apt-get in past tense) install. Well, I was right. So, let's discuss about how to do it in Debian.

Installing PHP/Ming on Debian GNU/Linux

Okay, I'll use $MINGINST to state Ming installation directory. For example, in my computer, the installation directory is /usr/apps/src/ming-0.1.1. So, if I say $MINGINST/php_ext, it means /usr/apps/src/ming-0.1.1/php_ext.
My initial (intuitive, again) step was trying to recompile the source code to get the shared object. The README stated that the first thing to do was simply typing make static. This produced $MINGINST/libming.a and some object files under $MINGINST/src. Next, still following the README, I changed directory to $MINGINST/php_ext and typed make. Whew... lots of errors. I read the error messages and they were about header files being not found. Maybe you think that it shouldn't be a problem if we have apt-got (err... perfect form of apt-get...) install php4-dev (for your information, I'm using the stable version). The fact is: it is, and it is because of the Debian directory layout that "confuses" php-config --includes being used inside Makefile. The same thing also applies for php-config --extension-dir.

With such a condition, in such a "quick and dirty" way, I modified Makefile so it became like this: (includes wrapped for formatting for this example)



prefix=`php-config --prefix`

includes=-I /usr/include/php4/main -I /usr/include/php4/Zend \
-I /usr/include/php4/ext/standard -I /usr/include/php4 \
-I /usr/include/php4/TSRM
extension=/usr/lib/php4/apache

DEFINES = -DHAVE_MING -DCOMPILE_DL_MING -DZEND_NEW_ERROR_HANDLING

CFILES = ming.c

php_ming.so: ming.o
	${CC} -shared -fpic ming.o ../libming.a -o php_ming.so -lm

ming.o: ${CFILES}
	${CC} ${DEFINES} -c ming.c -I. -I.. ${includes} 

clean:
	rm -f php_ming.so

install:
	cp php_ming.so ${extension} 
	echo "Don't forget to add 'extension=php_ming.so' to php.ini!"

Please notice the changes: two additional variables (includes and extension) and a few changes in the targets ming.o and install.
After the adjustments, I could make and make install successfully. As the message make install says, we should not forget to add extension=php_ming.so to php.ini (and something not mentioned, restart our web server). I did those things and I could later use the code shown in the next section.
I don't know whether we should do these tasks under other Debian-based distros like Corel Linux or Storm Linux. I haven't tried (even I have never installed any of them). I would be glad if someone can inform me about it.

Testing the Installation

After we have successfully installed PHP/Ming, we can try this code:

<?php
// create movie and set parameters
$movie=new SWFMovie();
$movie->setBackground(0xee,0xee,0xff);  // nice light blue
$movie->setDimension(800,600);
// draw rectangles
for($c=0;$c<5;$c++)
$shape=new SWFShape();
  
// set line width 20, with blue shade
  
$shape->setLine(20,0x00,0x00,$c*50);
  
$offset=$c*20;
  
$shape->movePenTo(100+$offset,100+$offset);
  
$shape->drawLineTo(700-$offset,100+$offset);
  
$shape->drawLineTo(700-$offset,500-$offset);
  
$shape->drawLineTo(100+$offset,500-$offset);
  
$shape->drawLineTo(100+$offset,100+$offset);
  
// add to canvas
  
$movie->add($shape);
  }
// send output
header("Content-Type:application/x-shockwave-flash"); 
$movie->output();
?>
We should be able see five rectangles with blue shades. If not, there may be something wrong with the installation.
Ending Words
The PHP binding for Ming relies heavily on the object-oriented feature of PHP. Please consult the documentation for further information. This article has brought you to the start, so you can now move on with your own movies.
Happy coding!
When not playing the music, Iman S. H. Suyoto probably plays around with software development tools. He currently works as a trainer for web development technologies in World Wide Web Institute Indonesia. He has published several articles in MIKRODATA, an Indonesian computer and programming publication. In 1997, he started doing web development. He has been using PHP since 2000.