Skip to content

Commit

Permalink
apply frankenphp.c changes from #1137
Browse files Browse the repository at this point in the history
  • Loading branch information
withinboredom committed Nov 22, 2024
1 parent 8903e24 commit 62c8319
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
28 changes: 28 additions & 0 deletions frankenphp.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,11 @@ PHP_FUNCTION(frankenphp_finish_request) { /* {{{ */
php_header();

if (ctx->has_active_request) {
#ifdef NEW_WORKER
go_frankenphp_finish_php_request(thread_index);
#else
go_frankenphp_finish_request(thread_index, false);
#endif
}

ctx->finished = true;
Expand Down Expand Up @@ -443,7 +447,11 @@ PHP_FUNCTION(frankenphp_handle_request) {

frankenphp_worker_request_shutdown();
ctx->has_active_request = false;
#ifdef NEW_WORKER
go_frankenphp_finish_worker_request(thread_index);
#else
go_frankenphp_finish_request(thread_index, true);
#endif

RETURN_TRUE;
}
Expand Down Expand Up @@ -832,15 +840,35 @@ static void *php_thread(void *arg) {
cfg_get_string("filter.default", &default_filter);
should_filter_var = default_filter != NULL;

#ifdef NEW_WORKER
go_frankenphp_on_thread_startup(thread_index);

while(true) {
char *scriptName = go_frankenphp_before_script_execution(thread_index);

// if the script name is NULL, the thread should exit
if (scriptName == NULL || scriptName[0] == '\0') {
break;
}

int exit_status = frankenphp_execute_script(scriptName);
go_frankenphp_after_script_execution(thread_index, exit_status);
}
#else
while (go_handle_request(thread_index)) {
}
#endif

go_frankenphp_release_known_variable_keys(thread_index);

#ifdef ZTS
ts_free_thread();
#endif

#ifdef NEW_WORKER
go_frankenphp_on_thread_shutdown(thread_index);
#endif

return NULL;
}

Expand Down
39 changes: 36 additions & 3 deletions new-worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,51 @@ func go_frankenphp_worker_handle_request_start(threadIndex C.uintptr_t) C.bool {
panic("not implemented")
}

// go_frankenphp_finish_request should flush the buffers and return the response.
// go_frankenphp_finish_php_request should flush the buffers and return the response.
// this does not mean the php code has finished executing,
// but that the request has been fully processed and can be returned to the client.
//
//export go_frankenphp_finish_request
func go_frankenphp_finish_request(threadIndex C.uintptr_t, isWorkerRequest bool) {
//export go_frankenphp_finish_php_request
func go_frankenphp_finish_php_request(threadIndex C.uintptr_t) {
thread := phpThreads[threadIndex]
r := thread.getActiveRequest()
fc := r.Context().Value(contextKey).(*FrankenPHPContext)
maybeCloseContext(fc)
}

// go_frankenphp_on_thread_startup is called when a thread is started.
//
//export go_frankenphp_on_thread_startup
func go_frankenphp_on_thread_startup(threadIndex C.uintptr_t) {
}

// go_frankenphp_before_script_execution is called before a request handling script is executed.
// it should return the script name to execute.
//
//export go_frankenphp_before_script_execution
func go_frankenphp_before_script_execution(threadIndex C.uintptr_t) *C.char {
panic("not implemented")
}

// go_frankenphp_after_script_execution is called after a request handling script is executed
//
//export go_frankenphp_after_script_execution
func go_frankenphp_after_script_execution(threadIndex C.uintptr_t, exitStatus C.int) {
}

// go_frankenphp_on_thread_shutdown is called when a thread is shutting down.
//
//export go_frankenphp_on_thread_shutdown
func go_frankenphp_on_thread_shutdown(threadIndex C.uintptr_t) {
}

// go_frankenphp_finish_worker_request is called when a worker has finished processing a request.
//
//export go_frankenphp_finish_worker_request
func go_frankenphp_finish_worker_request(threadIndex C.uintptr_t) {

}

// restartWorkersOnFileChanges restarts the workers on file changes.
func restartWorkersOnFileChanges(workerOpts []workerOpt) error {
panic("not implemented")
Expand Down

0 comments on commit 62c8319

Please sign in to comment.