Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PHPをGoで動かす

Avatar for chiroruxx chiroruxx
November 19, 2025

 PHPをGoで動かす

2025/11/19 Go Connect #10 の登壇資料です。

Avatar for chiroruxx

chiroruxx

November 19, 2025
Tweet

More Decks by chiroruxx

Other Decks in Technology

Transcript

  1. サンプルコード func main() { code := ` $apple = 'red';

    $banana = 'yellow'; $selected = 'banana'; echo "{$selected} is {$$selected}"; ` os.Exit( frankenphp.ExecutePHPCode(code) ) }
  2. サンプルコード func main() { code := ` $apple = 'red';

    $banana = 'yellow'; $selected = 'banana'; echo "{$selected} is {$$selected}"; ` os.Exit( frankenphp.ExecutePHPCode(code) ) }
  3. ExecutePHP Code func ExecutePHPCode(phpCode string) int { // Ensure extensions

    are registered before CLI execution registerExtensions() cCode := C.CString(phpCode) defer C.free(unsafe.Pointer(cCode)) return int( C.frankenphp_execute_script_cli( cCode, 0, nil, true ) ) }
  4. frankenphp _execute _script_cli int frankenphp_execute_script_cli(char *script, int argc, char **argv,

    bool eval) { // ... err = pthread_create(&thread, NULL, execute_script_cli, (void *)eval); if (err != 0) { return err; } err = pthread_join(thread, &exit_status); if (err != 0) { return err; } return (intptr_t)exit_status; }
  5. execute _script_cli static void *execute_script_cli(void *arg) { // ... zend_first_try

    { if (eval) { zend_eval_string_ex(cli_script, NULL, "Command line code", 1); } else { // ... } } zend_end_try(); exit_status = (void *)(intptr_t)EG(exit_status); php_embed_shutdown(); return exit_status; }