Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save abcarroll/ef2dbd1c7f4e6d21de4d7ea8f04943fb to your computer and use it in GitHub Desktop.
Save abcarroll/ef2dbd1c7f4e6d21de4d7ea8f04943fb to your computer and use it in GitHub Desktop.
PHP Embed Example
#include <stdio.h>
#include <iostream>
#include <thread>
#include <list>
#include <sapi/embed/php_embed.h>
int main(int argc, char* argv[]) {
PHP_EMBED_START_BLOCK(argc, argv)
std::list<std::shared_ptr<std::thread>> threads;
for (int i = 0; i < 50; i++) {
threads.push_back(std::make_shared<std::thread>([]{
ts_resource(0);
#if defined(PHP_WIN32) && defined(ZTS)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
for (int i = 0; i < 100; i++) {
zend_file_handle file_handle;
file_handle.type = ZEND_HANDLE_FILENAME;
file_handle.filename = "test.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 << "FINISHED" << std::endl;
}));
}
for(auto& thread: threads) {
thread->join();
}
PHP_EMBED_END_BLOCK()
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment