Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define TEST1 0
- #include <iostream>
- #include <thread>
- #include <main/php.h>
- #include <main/SAPI.h>
- #include <main/php_main.h>
- #if TEST1 == 1
- #include <php_embed.h>
- #endif
- zend_module_entry ips_module_entry = {
- STANDARD_MODULE_HEADER,
- "XYZ",
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NO_VERSION_YET,
- STANDARD_MODULE_PROPERTIES
- };
- static size_t php_embed_read_post(char *str, size_t str_length)
- {
- return 0;
- }
- static char* php_embed_read_cookies()
- {
- return NULL;
- }
- static size_t php_embed_ub_write(const char *str, size_t str_length)
- {
- std::cout << str;
- return str_length;
- }
- static void php_embed_flush(void *server_context)
- {
- //
- }
- static void php_embed_send_header(sapi_header_struct *sapi_header, void *server_context)
- {
- //
- }
- static void php_embed_log_message(char *message, int a)
- {
- fprintf(stderr, "%s\n", message);
- }
- static void php_embed_register_variables(zval *track_vars_array)
- {
- //
- }
- static int php_embed_startup(sapi_module_struct *sapi_module)
- {
- if (php_module_startup(sapi_module, NULL, 0) == FAILURE) {
- return FAILURE;
- }
- return SUCCESS;
- }
- #if TEST1 == 0
- sapi_module_struct php_embed_module = {
- "XYZ", /* name */
- "PHP for XYZ", /* pretty name */
- php_embed_startup, /* startup */
- php_module_shutdown_wrapper, /* shutdown */
- NULL, /* activate */
- NULL, /* deactivate */
- php_embed_ub_write, /* unbuffered write */
- php_embed_flush, /* flush */
- NULL, /* get uid */
- NULL, /* getenv */
- php_error, /* error handler */
- NULL, /* header handler */
- NULL, /* send headers handler */
- php_embed_send_header, /* send header handler */
- php_embed_read_post, /* read POST data */
- php_embed_read_cookies, /* read Cookies */
- php_embed_register_variables, /* register server variables */
- php_embed_log_message, /* Log message */
- NULL, /* Get request time */
- NULL, /* Child terminate */
- STANDARD_SAPI_MODULE_PROPERTIES
- };
- #endif
- int main(int argc, const char * argv[]) {
- tsrm_startup(128, 1, 0, NULL);
- #if TEST1 == 0
- sapi_startup(&php_embed_module);
- if (php_embed_module.startup(&php_embed_module) == FAILURE) {
- throw std::runtime_error("Could not start PHP!");
- }
- #endif
- #if TEST1 == 1
- int argc2 = 1;
- char* text = "embed4";
- char *argv2[2] = { text, NULL };
- php_embed_init(argc2, argv2);
- #endif
- for(int i = 0; i < 10; i++) {
- std::thread([&argv]{
- ts_resource(0);
- while(true){
- zend_file_handle file_handle;
- file_handle.type = ZEND_HANDLE_FILENAME;
- file_handle.filename = "/tmp/test1.php";
- file_handle.handle.fp = NULL;
- file_handle.opened_path = NULL;
- file_handle.free_filename = 0;
- if (php_request_startup() == FAILURE) {
- //std::cout << "ERR" << std::endl;
- php_request_shutdown(NULL);
- continue;
- }
- if(php_execute_script(&file_handle) == FAILURE)
- break;
- //std::cout << "RUN" << std::endl;
- php_request_shutdown(NULL);
- }
- std::cout << "DIED" << std::endl;
- }).detach();
- }
- while(true);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement