0
1 PHP
2008/01/22 at
photo by Sara Golemon (flickr.com/photos/pollita/2093670535/)
... (01/05 18:46)
10
PHP
•
•
    »
•
•CodeGen_PECL
   Extension
•
•             PC

• http://phpext.g.hatena.ne.jp/i_
  ogi/20080119/1200758118
PHP   (Extension)
PHP Extension
•C/C++

•PHP
•C           PHP
 »
     (PHP)
•C
             USB
 »libusb
•C
•
•
...
C
Extension       (   )
•mysql         DB
         PHP
 PDO
•imagick

•Xdebug
 PHP
Extension     (       )
PHP                       C

•json (JSON   )
•syck (YAML       )
Extension    (   )
Extension

•SimpleXML
Extension   (   )
•runkit


•operator
 PHP
•
•
    »
    »Sara
    »PHP
Extending and Embedding PHP
• Sara Golemon
• Yahoo! Inc

 runkit

•
•4   5
PHP5
•        ,
    ()
•
•
PHP4 / 5
C
• PHP
•
                5.2
    »5.1

             5.2.2
    »5.2.1

•C
PHP4 is DEAD!!!
•           PHP4

•PHP4
          PHP5
    »
welcome PHP5
•PHP5

 OOP
 »
 »interface
•SPL
•SimpleXML
PHP6
•Unicode

•
•
CodeGen_PECL
       Extension
• CodeGen_PECL   XML
• pecl-gen

•
•
•
CodeGen_PECL      ?
• XML                 PECL

•           XML

• PHP5     PEAR
  PHP4/5
                  4
    »5
ext_skel
• PHP4      ext_skel

•


•
• CodeGen_PECL         IF
• CodeGen_PECL
    »
    » http://www.m-takagi.org/
      docs/php/CodeGen_PECL/
•             PHP
       2
              ...
CodeGen_PECL
XML(Spec file)
XML                        (    )


•                (     )
• PECL
    »
•
    » C or C++, platform(unix, win,all)
    » ...
XML                  (       )
•       (function)
                         ) code
    »proto(
•
    »MINIT, RINIT
    »MSH...
XML                  (         )
•       (constant)
• ini
•
•

                         XML
•

•       quot;study1quot;
    »
PHP

•             : study1
•       : study1_func()
• ini              : study1.ini
•     : STUDY1_CONSTANT
• hello world
•
  <?php
  function study1_greeting($name = quot;quot;)
  {
    if (strlen($name)) {
      echo quot;Hello,...
•
     »PHP

    //
    void funcname(void);

    // int             int
    int funcname(int param);

            Example...
//    1                              2
//
string funcname(string param1
          [[, string param2], string param3]);
//
...
•
•
    »
    »
•
•                       1
•
•

void study1_greeting([string name])
XML(Spec   )
• XML                      <extension>
• name              →
            quot;study1quot;
  »
<?xml version=quot;1.0quot; ...
(function            )
• name            →
• <proto>

<function name=quot;study1_greetingquot;>
  <proto>void study1_greet...
(code   )
•C
•
• PHP
•           : string name
•
    »const char *name
            int name_len
    »
•
    »
• http://www.m-
  takagi.org/docs/php/CodeGen_P
  ECL/x304.html#AEN377
<code>
  if (name_len) {
    //php_printf(quot;Hello, %s%squot;,
                 name, PHP_EOL);
    php_printf(quot;Hell...
(function      test      )
•
• test



<test>
  <code>                </code>
  <result mode=quot;plainquot;>   </result>
...
(function        test      )
•


<test>
  <code>study1_greeting();study1_gre
eting(quot;Japanquot;);</code>
  <result mode...
<?xml version=quot;1.0quot; ?>
<!DOCTYPE extension SYSTEM quot;../extension.dtdquot;>
<extension name=quot;study1quot;>
  ...
XML

specfile.xml
pecl-gen
pecl-
pecl-gen specfile.xml
OK
$ pecl-gen specfile.xml
Warning: no 'version' attribute given for
<extension>, assuming 1.1.0
       this may lead to c...
study1
             cd

     $ cd study1
•phpize (          )
•./configure
•make
•make test
•sudo make install
phpize
$ phpize
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20060613
Zend Extension Api No...
./configure
$ ./configure
checking for grep that handles long lines and
-e... /bin/grep
checking for egrep... /bin/grep -E...
make
$ make
...
----------------------------------------------------------------------
Libraries have been installed in:
 ...
make test
•


•                make test
    php.ini   extension
make test
$ make test
...
=====================================================================
CWD         : /home/iogiwa...
sudo make install
$ sudo make install
Installing shared extensions:
/usr/lib/php5/20060613+lfs/
•
    »-d extension=○

    »-r


$ php -dextension=study1.so –r
'study1_greeting();'
Hello, World!
CodeGen_PECL
•CodeGen_PECL   ext_skel




•
•
    »http://gihyo.jp/dev/serial/01/php
     -module/0002?page=2
•
•C
• config.m4
第1回PHP拡張勉強会
第1回PHP拡張勉強会
第1回PHP拡張勉強会
第1回PHP拡張勉強会
第1回PHP拡張勉強会
第1回PHP拡張勉強会
第1回PHP拡張勉強会
第1回PHP拡張勉強会
第1回PHP拡張勉強会
第1回PHP拡張勉強会
第1回PHP拡張勉強会
第1回PHP拡張勉強会
第1回PHP拡張勉強会
Upcoming SlideShare
Loading in...5
×

第1回PHP拡張勉強会

13,681

Published on

第1回PHP拡張勉強会用資料
http://events.php.gr.jp/event.php/event_show/34
http://d.hatena.ne.jp/i_ogi/20080115/ExtStudyVol1

Published in: Technology
1 Comment
4 Likes
Statistics
Notes
  • If you want to check out a cool Drupal/PHP based site visit OracleLink.com - The Oracle Community Network

    http://www.oraclelink.com



    Built by CTISN
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
13,681
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
89
Comments
1
Likes
4
Embeds 0
No embeds

No notes for slide

Transcript of "第1回PHP拡張勉強会"

  1. 1. 1 PHP 2008/01/22 at photo by Sara Golemon (flickr.com/photos/pollita/2093670535/)
  2. 2. ... (01/05 18:46)
  3. 3. 10
  4. 4. PHP • • » •
  5. 5. •CodeGen_PECL Extension •
  6. 6. • PC • http://phpext.g.hatena.ne.jp/i_ ogi/20080119/1200758118
  7. 7. PHP (Extension)
  8. 8. PHP Extension •C/C++ •PHP
  9. 9. •C PHP » (PHP) •C USB »libusb
  10. 10. •C • •
  11. 11. ... C
  12. 12. Extension ( ) •mysql DB PHP PDO •imagick •Xdebug PHP
  13. 13. Extension ( ) PHP C •json (JSON ) •syck (YAML )
  14. 14. Extension ( ) Extension •SimpleXML
  15. 15. Extension ( ) •runkit •operator PHP
  16. 16. • • » »Sara »PHP
  17. 17. Extending and Embedding PHP • Sara Golemon • Yahoo! Inc runkit • •4 5
  18. 18. PHP5 • , () • •
  19. 19. PHP4 / 5
  20. 20. C • PHP • 5.2 »5.1 5.2.2 »5.2.1 •C
  21. 21. PHP4 is DEAD!!! • PHP4 •PHP4 PHP5 »
  22. 22. welcome PHP5 •PHP5 OOP » »interface •SPL •SimpleXML
  23. 23. PHP6 •Unicode • •
  24. 24. CodeGen_PECL Extension
  25. 25. • CodeGen_PECL XML • pecl-gen • • •
  26. 26. CodeGen_PECL ? • XML PECL • XML • PHP5 PEAR PHP4/5 4 »5
  27. 27. ext_skel • PHP4 ext_skel • • • CodeGen_PECL IF
  28. 28. • CodeGen_PECL » » http://www.m-takagi.org/ docs/php/CodeGen_PECL/ • PHP 2 gihyo.jp » » http://gihyo.jp/dev/serial/01/php- module/0002
  29. 29. CodeGen_PECL XML(Spec file)
  30. 30. XML ( ) • ( ) • PECL » • » C or C++, platform(unix, win,all) » --with (header, lib path) Extension »
  31. 31. XML ( ) • (function) ) code »proto( • »MINIT, RINIT »MSHUTDOWN, RSHUTDOWN »MINFO • OOP PHP4 OOP »CodeGen
  32. 32. XML ( ) • (constant) • ini • • XML
  33. 33. • • quot;study1quot; »
  34. 34. PHP • : study1 • : study1_func() • ini : study1.ini • : STUDY1_CONSTANT
  35. 35. • hello world • <?php function study1_greeting($name = quot;quot;) { if (strlen($name)) { echo quot;Hello, $name!quot;, PHP_EOL; } else { echo quot;Hello, World!quot;, PHP_EOL; } } ?>
  36. 36. • »PHP // void funcname(void); // int int int funcname(int param); Example 12.
  37. 37. // 1 2 // string funcname(string param1 [[, string param2], string param3]); // int funcname([int param = 42]); // int funcname(string param1, ...); // object foo funcname(resource bar param1); Example 12.
  38. 38. • • » » •
  39. 39. • 1 • • void study1_greeting([string name])
  40. 40. XML(Spec )
  41. 41. • XML <extension> • name → quot;study1quot; » <?xml version=quot;1.0quot; ?> <!DOCTYPE extension SYSTEM quot;../extension.dtdquot;> <extension name=quot;study1quot;> </extension>
  42. 42. (function ) • name → • <proto> <function name=quot;study1_greetingquot;> <proto>void study1_greeting([string name])</proto> <code> </code> <test> </test> </function>
  43. 43. (code ) •C •
  44. 44. • PHP • : string name • »const char *name int name_len » • »
  45. 45. • http://www.m- takagi.org/docs/php/CodeGen_P ECL/x304.html#AEN377
  46. 46. <code> if (name_len) { //php_printf(quot;Hello, %s%squot;, name, PHP_EOL); php_printf(quot;Hello, quot;); PHPWRITE(name, name_len); php_printf(quot;!%squot;, PHP_EOL); } else { php_printf(quot;Hello, World!%squot;, PHP_EOL); } </code>
  47. 47. (function test ) • • test <test> <code> </code> <result mode=quot;plainquot;> </result> </test>
  48. 48. (function test ) • <test> <code>study1_greeting();study1_gre eting(quot;Japanquot;);</code> <result mode=quot;plainquot;>Hello, World! Hello, Japan!</result> </test>
  49. 49. <?xml version=quot;1.0quot; ?> <!DOCTYPE extension SYSTEM quot;../extension.dtdquot;> <extension name=quot;study1quot;> <function name=quot;study1_greetingquot;> <proto>void study1_greeting([string name])</proto> <code> if (name_len) { //php_printf(quot;Hello, %s%squot;, name, PHP_EOL); php_printf(quot;Hello, quot;); PHPWRITE(name, name_len); php_printf(quot;!%squot;, PHP_EOL); } else { php_printf(quot;Hello, World!%squot;, PHP_EOL); } </code> <test> <code>study1_greeting();study1_greeting(quot;Japanquot;);</code> <result mode=quot;plainquot;>Hello, World! Hello, Japan!</result> </test> </function> </extension>
  50. 50. XML specfile.xml
  51. 51. pecl-gen
  52. 52. pecl- pecl-gen specfile.xml
  53. 53. OK $ pecl-gen specfile.xml Warning: no 'version' attribute given for <extension>, assuming 1.1.0 this may lead to compile errors if your spec file was created for an older version Creating 'study1' extension in './study1' Your extension has been created in directory ./study1. See ./study1/README and/or ./study1/INSTALL for further instructions.
  54. 54. study1 cd $ cd study1
  55. 55. •phpize ( ) •./configure •make •make test •sudo make install
  56. 56. phpize $ phpize Configuring for: PHP Api Version: 20041225 Zend Module Api No: 20060613 Zend Extension Api No: 220060519
  57. 57. ./configure $ ./configure checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for a sed that does not truncate output... /bin/sed checking for gcc... gcc checking for C compiler default output file name... a.out ... appending configuration tag quot;F77quot; to libtool configure: creating ./config.status config.status: creating config.h
  58. 58. make $ make ... ---------------------------------------------------------------------- Libraries have been installed in: /home/iogiwara/work/extstudy/080122/2/study1/modules If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the `-LLIBDIR' flag during linking and do at least one of the following: - add LIBDIR to the `LD_LIBRARY_PATH' environment variable during execution - add LIBDIR to the `LD_RUN_PATH' environment variable during linking - use the `-Wl,--rpath -Wl,LIBDIR' linker flag - have your system administrator add LIBDIR to `/etc/ld.so.conf' See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages. ---------------------------------------------------------------------- Build complete. Don't forget to run 'make test'.
  59. 59. make test • • make test php.ini extension
  60. 60. make test $ make test ... ===================================================================== CWD : /home/iogiwara/work/extstudy/080122/2/study1 PHP : /usr/bin/php PHP_SAPI : cli PHP_VERSION : 5.2.3-1ubuntu6.3 ZEND_VERSION: 2.2.0 PHP_OS : Linux - Linux ubuntu-desktop 2.6.22-14-generic #1 ... INI actual : /etc/php5/cli/php.ini More .INIs : Extra dirs : ===================================================================== Running selected tests. PASS study1_greeting() function [tests/study1_greeting.phpt] ===================================================================== Number of tests : 1 1 Tests skipped : 0 ( 0.0%) -------- Tests warned : 0 ( 0.0%) ( 0.0%) Tests failed : 0 ( 0.0%) ( 0.0%) Tests passed : 1 (100.0%) (100.0%) --------------------------------------------------------------------- Time taken : 0 seconds =====================================================================
  61. 61. sudo make install $ sudo make install Installing shared extensions: /usr/lib/php5/20060613+lfs/
  62. 62. • »-d extension=○ »-r $ php -dextension=study1.so –r 'study1_greeting();' Hello, World!
  63. 63. CodeGen_PECL
  64. 64. •CodeGen_PECL ext_skel •
  65. 65. • »http://gihyo.jp/dev/serial/01/php -module/0002?page=2 • •C • config.m4
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×