[PHP] User Defined Extension
Ϊ PHP Ìí¼ÓÀ©Õ¹¿âÊÇÒ»¼þ¼òµ¥µÄÊÂÇé¡£²»¹ýÊ×ÏÈÄã×îºÃ»áÒ»µãµãC/C++±à³Ì¼¼Êõ£¬²¢ÇÒ¶ÔMakefileÓÐÒ»¶¨µÄÁ˽⡣
ÒÔÏÂÊÇÔÚ Linux ϵÄÒ»¸ö¼òµ¥Àý×Ó£º
Ê×ÏÈ£¬½øÈë php Ô´´úÂëĿ¼£¨¼ÙÉèΪ PHP_SRC£¬ÒÔÏÂͬ£©£¬Ê¹Óà php ×Ô´øµÄ ext_skel ¹¤¾ßÉú³ÉÒ»¸öÐÂÀ©Õ¹ mk4php£º
cd PHP_SRC/etc;
./ext_skel --extname=mk4php
Õý³£Çé¿öÏÂÄú»á¿´µ½ÀàËÆÕâÑùµÄÊä³ö£º
Creating directory mk4php
Creating basic files: config.m4 config.w32 .cvsignore mk4php.c php_mk4php.h CREDITS EXPERIMENTAL tests/001.phpt mk4php.php [done].
To use your new extension, you will have to execute the following steps:
1. $ cd ..
2. $ vi ext/mk4php/config.m4
3. $ ./buildconf
4. $ ./configure --[with|enable]-mk4php
5. $ make
6. $ ./php -f ext/mk4php/mk4php.php
7. $ vi ext/mk4php/mk4php.c
8. $ make
Repeat steps 3-6 until you are satisfied with ext/mk4php/config.m4 and
step 6 confirms that your module is compiled into PHP. Then, start writing
code and repeat the last two steps as often as necessary.
´Ëʱ»áÔÚ ext/ Ŀ¼ÏÂÉú³ÉÒ»¸öÒÔ mk4php ÃüÃûµÄĿ¼£¬½øÈ¥¿´¿´¡£
±à¼ ext/mk4php/ Ŀ¼ÏÂÃæµÄ config.m4 Îļþ£¬ÕÒµ½ÏÂÃæÈýÐУ¬É¾µôÇ°ÃæµÄ dnl ǰ׺£º
dnl PHP_ARG_WITH(mk4php, for mk4php support,
dnl Make sure that the comment is aligned:
dnl [ --with-mk4php Include mk4php support])
˵Ã÷£º
1. dnl ÊÇ×¢ÊÍ£¬É¾µô±íʾʹ¸ÄÐÐÉúЧ£¬·ñÔò make µÄʱºò²»»áÉú³ÉÏàÓ¦µÄ modules
2. Ò²¿ÉÒÔʹÓÃÏÂÃæ°¤×ŵĹØÓÚ --enable-mk4php ÄÇÈýÐУ¬Á½ÕßµÄÇø±ðÔÚÓÚÄãµÄÀ©Õ¹ÊÇ·ñÐèÒªÒýÓÃÍⲿµÄ¿â
È»ºó¾ÍÊÇ configure; make; make install
configure µÄʱºò£¬Èç¹ûÄãµÄ apxs ºÍ php-config ²»ÔÚĬÈÏ·¾¶ÉÏ£¬ÔòÐèÒªÖ¸¶¨ËüÃÇ
./configure --with-mk4php --with-apxs=/usr/local/apache/bin/apxs --with-php-config=/usr/local/php/bin/php-config
make
make install
˵Ã÷£º
1. make ³É¹¦Ö®ºó»áÔÚ ext/mk4php/modules/ ÏÂÉú³ÉÏàÓ¦µÄ .so Îļþ
2. make install ¾ÍÊÇ°Ñ modules/* ¸´ÖƵ½ php µÄ extensions Ŀ¼
ÔÙÏÂÀ´¾ÍÊÇÔÚ php.ini ÀïÌí¼ÓÒ»ÐУº
extension=mk4php.so
×îºó¼ì²éÒ»ÏÂÊÇ·ñ°²×°
Ïà¹ØÎĵµ£º
µ±ÄúÔËÐÐÒ»¸öÓ¦ÓóÌÐòʱ£¬Äú»á´ò¿ªËü£¬×öЩ¸ü¸Ä£¬È»ºó¹Ø±ÕËü¡£ÕâºÜÏñÒ»´Î»á»°¡£¼ÆËã»úÇå³þÄãÊÇË¡£ËüÖªµÀÄãºÎʱÆô¶¯Ó¦ÓóÌÐò£¬²¢ÔÚºÎʱÖÕÖ¹¡£µ«ÊÇÔÚÒòÌØÍøÉÏ£¬´æÔÚÒ»¸öÎÊÌ⣺·þÎñÆ÷²»ÖªµÀÄãÊÇËÒÔ¼°Äã×öʲô£¬ÕâÊÇÓÉÓÚ HTTP µØÖ·²»ÄÜά³Ö״̬¡£
ͨ¹ýÔÚ·þÎñÆ÷ÉÏ´æ´¢Óû§ÐÅÏ¢ÒÔ±ãËæºóʹÓã¬PHP session ½â¾öÁËÕâ¸öÎÊÌ⣨±ÈÈç ......
²»µÃ²»×ÔÒÑдһ¸ö.XML
µÄ²Ù×÷һֱûÓÐÓùý.ÏÂÃæÊÇ×Ô¼ºËѼ¯µÄXML²Ù×÷Àà
DOMDocumentÏà¹ØµÄÄÚÈÝ.
ÊôÐÔ:
Attributes ´æ´¢½ÚµãµÄÊôÐÔÁбí(Ö»¶Á)
childNodes
´æ´¢½ÚµãµÄ×Ó½ÚµãÁбí(Ö»¶Á)
dataType ·µ»Ø´Ë½ÚµãµÄÊý¾ÝÀàÐÍ
Definition ÒÔDTD»òXMLģʽ¸ø³öµÄ½ÚµãµÄ¶¨Òå(Ö»¶Á)
Doctype Ö¸¶¨ÎĵµÀàÐͽڵã(Ö»¶Á)
doc ......
Output Control º¯Êý¿ÉÒÔÈÃÄã×ÔÓÉ¿ØÖƽű¾ÖÐÊý¾ÝµÄÊä³ö¡£Ëü·Ç³£µØÓÐÓã¬ÌرðÊǶÔÓÚ£ºµ±ÄãÏëÔÚÊý¾ÝÒѾÊä³öºó£¬ÔÙÊä³öÎļþÍ·µÄÇé¿ö¡£Êä³ö¿ØÖƺ¯Êý²»¶ÔʹÓà header() »ò setcookie(), ·¢Ë͵ÄÎļþÍ·ÐÅÏ¢²úÉúÓ°Ïì,Ö»¶ÔÄÇЩÀàËÆÓÚ echo() ºÍ PHP ´úÂëµÄÊý¾Ý¿éÓÐ×÷Óá£
ÎÒÃÇÏȾÙÒ»¸ö¼òµ¥µÄÀý×Ó£¬Èôó¼Ò¶ÔOutput ControlÓÐÒ»¸ö´ ......
ΪÁËÉîÈëÁ˽âPHP£¬ÒÔ¼°¸ü¼Ó±ãÀûµÄʹÓÃPHPΪÎÒÃÇ·þÎñ£¬±¾Õ½ÚÖ÷Òª½éÉÜPHPµÄ»ù±¾Óï·¨¡£
Ò»¡¢´ÓHTMLÖзÖÀë
PHP µÄ½Å±¾ÓÉÎļþÖÐÒ»¶ÔÌØÊâµÄ±ê¼ÇËùÒýÆðµÄÄÚÈÝ£¬µ±½âÊÍÆ÷·ÖÎöÒ»¸öÎļþʱ£¬ËùÓÐÌØÊâ±ê¼ÇÍâµÄÆÕͨÎļþ£¬½âÊÍÆ÷²»¶ÔÆä×öÈκδ¦Àí£¬¶øÌØÊâ±ê¼ÇÄÚÎļþ½«×÷Ϊ PHP ´úÂë±»½âÊÍÆ÷·ÖÎöÖ´ÐС£¸ÃÔËÐлúÖƽ«ÔÊÐíÄúÔÚ HTML ÖÐǶÈë ......