#include "php.h"
#include "SAPI.h"
#ifdef ZTS
#include "TSRM.h"
#endif
#include "php_main.h"
#include "zend_stream.h"
#include "zend_execute.h"
void folk_zts_thread_init(void) {
#ifdef ZTS
(void)ts_resource(0);
#ifdef PHP_WIN32
ZEND_TSRMLS_CACHE_UPDATE();
#endif
#endif
}
void folk_zts_thread_shutdown(void) {
#ifdef ZTS
ts_free_thread();
#endif
}
int folk_zts_request_startup(void) {
return php_request_startup();
}
void folk_zts_request_shutdown(void) {
php_request_shutdown(NULL);
}
int folk_zts_execute_script(const char *filename) {
FILE *fp = fopen(filename, "rb");
if (!fp) return 0;
int c1 = fgetc(fp);
int c2 = fgetc(fp);
if (c1 == '#' && c2 == '!') {
int c;
while ((c = fgetc(fp)) != EOF && c != '\n') {}
} else {
rewind(fp);
}
zend_file_handle file_handle;
zend_stream_init_fp(&file_handle, fp, filename);
int ret = php_execute_script(&file_handle);
zend_destroy_file_handle(&file_handle);
return ret;
}
int folk_zts_call_dispatch(const char *func_name, zval *method_zval, zval *params_zval, zval *retval) {
zval fname;
ZVAL_STRING(&fname, func_name);
zval args[2];
ZVAL_COPY(&args[0], method_zval);
ZVAL_COPY(&args[1], params_zval);
int result = call_user_function(
CG(function_table),
NULL,
&fname,
retval,
2,
args
);
zval_ptr_dtor(&args[0]);
zval_ptr_dtor(&args[1]);
zval_ptr_dtor(&fname);
return result;
}
int folk_zts_is_enabled(void) {
#ifdef ZTS
return 1;
#else
return 0;
#endif
}