Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

sample code
Thursday, November 2nd, 2006 at 10:59:11am UTC 

  1. <?php
  2.   sample4_hello_world();
  3. ?>
  4.  
  5.  
  6. which uses the following simple extension
  7.  
  8.  
  9. ------------------------- php_sample4.h ----------------------
  10.  
  11. #ifndef PHP_SAMPLE4_H
  12. /* Prevent double inclusion */
  13. #define PHP_SAMPLE4_H
  14.  
  15. /* Define Extension Properties */
  16. #define PHP_SAMPLE4_EXTNAME    "sample4"
  17. #define PHP_SAMPLE4_EXTVER    "1.0"
  18.  
  19. /* Import configure options
  20.    when building outside of
  21.    the PHP source tree */
  22. #ifdef HAVE_CONFIG_H
  23. #include "config.h"
  24. #endif
  25.  
  26. /* Include PHP Standard Header */
  27. #include "php.h"
  28.  
  29. /* Define the entry point symbol
  30.  * Zend will use when loading this module
  31.  */
  32. extern zend_module_entry sample4_module_entry;
  33. #define phpext_sample4_ptr &sample4_module_entry
  34.  
  35. PHP_MINIT_FUNCTION(sample4);
  36. PHP_MSHUTDOWN_FUNCTION(sample4);
  37. PHP_FUNCTION(sample4_hello_world);
  38.  
  39. #endif /* PHP_SAMPLE4_H */
  40. ------------------------- php_sample4.h ----------------------
  41.  
  42.  
  43. ------------------------- php_sample4.c ----------------------
  44.  
  45. #include "php_sample4.h"
  46. #include "ext/standard/info.h"
  47. #include "main/sapi.h"
  48. #include "php_ini.h"
  49.  
  50. ZEND_INI_MH(php_sample4_modify_greeting)
  51. {
  52. #ifdef ZTS
  53.     THREAD_T thread = tsrm_thread_id();
  54. #else
  55.     void *thread = NULL;
  56. #endif
  57.  
  58.     if (new_value_length == 0 ) {
  59.         return FAILURE;
  60.     }
  61.  
  62.     php_printf("sample 4: thread %p greeting modified..new value is %s\n",  thread, new_value);
  63.     return SUCCESS;
  64. }
  65.  
  66. PHP_INI_BEGIN()
  67.     PHP_INI_ENTRY("sample4.greeting", "Hello World", PHP_INI_ALL, php_sample4_modify_greeting)
  68. PHP_INI_END()
  69.  
  70. PHP_MINIT_FUNCTION(sample4)
  71. {
  72. #ifdef ZTS
  73.     THREAD_T thread = tsrm_thread_id();
  74. #else
  75.     void *thread= NULL;
  76. #endif
  77.  
  78.     php_printf(">> sample 4: thread %p minit \n", thread);
  79.     REGISTER_INI_ENTRIES();
  80.     php_printf("<< sample 4: thread %p minit \n", thread);
  81.     return SUCCESS;
  82. }
  83.  
  84. PHP_MSHUTDOWN_FUNCTION(sample4)
  85. {
  86.     UNREGISTER_INI_ENTRIES();
  87.     return SUCCESS;
  88. }
  89.  
  90. PHP_FUNCTION(sample4_hello_world)
  91. {
  92.     const char *greeting = INI_STR("sample4.greeting");
  93.     php_printf("%s\n", greeting);
  94. }
  95.  
  96. static function_entry php_sample4_functions[] = {
  97.     PHP_FE(sample4_hello_world, NULL)
  98.     { NULL, NULL, NULL }
  99. };
  100.  
  101. zend_module_entry sample4_module_entry = {
  102. #if ZEND_MODULE_API_NO >= 20010901
  103.     STANDARD_MODULE_HEADER,
  104. #endif
  105.     PHP_SAMPLE4_EXTNAME,
  106.     php_sample4_functions,
  107.     PHP_MINIT(sample4),
  108.     PHP_MSHUTDOWN(sample4),
  109.     NULL,
  110.     NULL,
  111.     NULL,
  112. #if ZEND_MODULE_API_NO >= 20010901
  113.     PHP_SAMPLE4_EXTVER,
  114. #endif
  115.     STANDARD_MODULE_PROPERTIES
  116. };
  117.  
  118. #ifdef COMPILE_DL_SAMPLE4
  119. ZEND_GET_MODULE(sample4)
  120. #endif
  121.  
  122.  
  123. ------------------------- php_sample4.c ----------------------

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right worth-right