README.NEW-OUTPUT-API 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. API adjustment to the old output control code:
  2. Everything now resides beneath the php_output namespace,
  3. and there's an API call for every output handler op.
  4. Checking output control layers status:
  5. // Using OG()
  6. php_output_get_status();
  7. Starting the default output handler:
  8. // php_start_ob_buffer(NULL, 0, 1);
  9. php_output_start_default();
  10. Starting an user handler by zval:
  11. // php_start_ob_buffer(zhandler, chunk_size, erase);
  12. php_output_start_user(zhandler, chunk_size, flags);
  13. Starting an internal handler without context:
  14. // php_ob_set_internal_handler(my_php_output_handler_func_t, buffer_size, "output handler name", erase);
  15. php_output_start_internal(handler_name, handler_name_len, my_php_output_handler_func_t, chunk_size, flags);
  16. Starting an internal handler with context:
  17. // not possible with old API
  18. php_output_handler *h;
  19. h = php_output_handler_create_internal(handler_name, handler_name_len, my_php_output_handler_context_func_t, chunk_size, flags);
  20. php_output_handler_set_context(h, my_context, my_context_dtor);
  21. php_output_handler_start(h);
  22. Testing whether a certain output handler has already been started:
  23. // php_ob_handler_used("output handler name");
  24. php_output_handler_started(handler_name, handler_name_len);
  25. Flushing one output buffer:
  26. // php_end_ob_buffer(1, 1);
  27. php_output_flush();
  28. Flushing all output buffers:
  29. // not possible with old API
  30. php_output_flush_all();
  31. Cleaning one output buffer:
  32. // php_ob_end_buffer(0, 1);
  33. php_output_clean();
  34. Cleaning all output buffers:
  35. // not possible with old API
  36. php_output_clean_all();
  37. Discarding one output buffer:
  38. // php_ob_end_buffer(0, 0);
  39. php_output_discard();
  40. Discarding all output buffers:
  41. // php_ob_end_buffers(0);
  42. php_output_discard_all();
  43. Stopping (and dropping) one output buffer:
  44. // php_ob_end_buffer(1, 0)
  45. php_output_end();
  46. Stopping (and dropping) all output buffers:
  47. // php_ob_end_buffers(1, 0);
  48. php_output_end_all();
  49. Retrieving output buffers contents:
  50. // php_ob_get_buffer(zstring);
  51. php_output_get_contents(zstring);
  52. Retrieving output buffers length:
  53. // php_ob_get_length(zlength);
  54. php_output_get_length(zlength);
  55. Retrieving output buffering level:
  56. // OG(nesting_level);
  57. php_output_get_level();
  58. Issue a warning because of an output handler conflict:
  59. // php_ob_init_conflict("to be started handler name", "to be tested if already started handler name");
  60. php_output_handler_conflict(new_handler_name, new_handler_name_len, set_handler_name, set_handler_name_len);
  61. Registering a conflict checking function, which will be checked prior starting the handler:
  62. // not possible with old API, unless hardcoding into output.c
  63. php_output_handler_conflict_register(handler_name, handler_name_len, my_php_output_handler_conflict_check_t);
  64. Registering a reverse conflict checking function, which will be checked prior starting the specified foreign handler:
  65. // not possible with old API
  66. php_output_handler_reverse_conflict_register(foreign_handler_name, foreign_handler_name_len, my_php_output_handler_conflict_check_t);
  67. Facilitating a context from within an output handler callable with ob_start():
  68. // not possible with old API
  69. php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_GET_OPAQ, (void *) &custom_ctx_ptr_ptr);
  70. Disabling of the output handler by itself:
  71. //not possible with old API
  72. php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_DISABLE, NULL);
  73. Marking an output handler immutable by itself because of irreversibility of its operation:
  74. // not possible with old API
  75. php_output_handler_hook(PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE, NULL);
  76. Restarting the output handler because of a CLEAN operation:
  77. // not possible with old API
  78. if (flags & PHP_OUTPUT_HANDLER_CLEAN) { ... }
  79. Recognizing by the output handler itself if it gets discarded:
  80. // not possible with old API
  81. if ((flags & PHP_OUTPUT_HANDLER_CLEAN) && (flags & PHP_OUTPUT_HANDLER_FINAL)) { ... }
  82. Output handler hooks
  83. The output handler can change its abilities at runtime. Eg. the gz handler can
  84. remove the CLEANABLE and REMOVABLE bits when the first output has passed through it;
  85. or handlers implemented in C to be used with ob_start() can contain a non-global
  86. context:
  87. PHP_OUTPUT_HANDLER_HOOK_GET_OPAQ
  88. pass a void*** pointer as second arg to receive the address of a pointer
  89. pointer to the opaque field of the output handler context
  90. PHP_OUTPUT_HANDLER_HOOK_GET_FLAGS
  91. pass a int* pointer as second arg to receive the flags set for the output handler
  92. PHP_OUTPUT_HANDLER_HOOK_GET_LEVEL
  93. pass a int* pointer as second arg to receive the level of this output handler
  94. (starts with 0)
  95. PHP_OUTPUT_HANDLER_HOOK_IMMUTABLE
  96. the second arg is ignored; marks the output handler to be neither cleanable
  97. nor removable
  98. PHP_OUTPUT_HANDLER_HOOK_DISABLE
  99. the second arg is ignored; marks the output handler as disabled
  100. Open questions
  101. Should the userland API be adjusted and unified?
  102. Many bits of the manual (and very first implementation) do not comply
  103. with the behaviour of the current (to be obsoleted) code, thus should
  104. the manual or the behaviour be adjusted?
  105. END