Skip to content

Commit a7ba434

Browse files
raphaelcoefficburgesQ
authored andcommitted
feat: add frankenphp_log_message() as a PHP function
1 parent 41cb2bb commit a7ba434

4 files changed

Lines changed: 35 additions & 6 deletions

File tree

frankenphp.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,19 @@ PHP_FUNCTION(mercure_publish) {
550550
RETURN_THROWS();
551551
}
552552

553+
PHP_FUNCTION(frankenphp_log_message) {
554+
char *message = NULL;
555+
size_t message_len = 0;
556+
zend_long level = 0;
557+
558+
ZEND_PARSE_PARAMETERS_START(2, 2)
559+
Z_PARAM_STRING(message, message_len)
560+
Z_PARAM_LONG(level)
561+
ZEND_PARSE_PARAMETERS_END();
562+
563+
go_log_n(message, message_len, (int)level);
564+
}
565+
553566
PHP_MINIT_FUNCTION(frankenphp) {
554567
zend_function *func;
555568

frankenphp.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,16 @@ func go_read_cookies(threadIndex C.uintptr_t) *C.char {
630630
func go_log(threadIndex C.uintptr_t, message *C.char, level C.int) {
631631
ctx := phpThreads[threadIndex].context()
632632
m := C.GoString(message)
633+
phpLog(m, level)
634+
}
635+
636+
//export go_log_n
637+
func go_log_n(message *C.char, len C.int, level C.int) {
638+
m := C.GoStringN(message, len)
639+
phpLog(m, level)
640+
}
633641

642+
func phpLog(m string, level C.int) {
634643
var le syslogLevel
635644
if level < C.int(syslogLevelEmerg) || level > C.int(syslogLevelDebug) {
636645
le = syslogLevelInfo

frankenphp.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ function apache_response_headers(): array|bool {}
3636
* @param string|string[] $topics
3737
*/
3838
function mercure_publish(string|array $topics, string $data = '', bool $private = false, ?string $id = null, ?string $type = null, ?int $retry = null): string {}
39+
40+
function frankenphp_log_message(str $message, int $level): void {}

frankenphp_arginfo.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: cd534a8394f535a600bf45a333955d23b5154756 */
2+
* Stub hash: 4005bdacf910203ece3c3074cc6a067dc57f86ac */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_frankenphp_handle_request, 0, 1, _IS_BOOL, 0)
55
ZEND_ARG_TYPE_INFO(0, callback, IS_CALLABLE, 0)
@@ -35,25 +35,30 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mercure_publish, 0, 1, IS_STRING
3535
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, retry, IS_LONG, 1, "null")
3636
ZEND_END_ARG_INFO()
3737

38+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_frankenphp_log_message, 0, 2, IS_VOID, 0)
39+
ZEND_ARG_OBJ_INFO(0, message, str, 0)
40+
ZEND_ARG_TYPE_INFO(0, level, IS_LONG, 0)
41+
ZEND_END_ARG_INFO()
3842

3943
ZEND_FUNCTION(frankenphp_handle_request);
4044
ZEND_FUNCTION(headers_send);
4145
ZEND_FUNCTION(frankenphp_finish_request);
4246
ZEND_FUNCTION(frankenphp_request_headers);
4347
ZEND_FUNCTION(frankenphp_response_headers);
4448
ZEND_FUNCTION(mercure_publish);
45-
49+
ZEND_FUNCTION(frankenphp_log_message);
4650

4751
static const zend_function_entry ext_functions[] = {
4852
ZEND_FE(frankenphp_handle_request, arginfo_frankenphp_handle_request)
4953
ZEND_FE(headers_send, arginfo_headers_send)
5054
ZEND_FE(frankenphp_finish_request, arginfo_frankenphp_finish_request)
51-
ZEND_FALIAS(fastcgi_finish_request, frankenphp_finish_request, arginfo_fastcgi_finish_request)
55+
ZEND_RAW_FENTRY("fastcgi_finish_request", zif_frankenphp_finish_request, arginfo_fastcgi_finish_request, 0, NULL, NULL)
5256
ZEND_FE(frankenphp_request_headers, arginfo_frankenphp_request_headers)
53-
ZEND_FALIAS(apache_request_headers, frankenphp_request_headers, arginfo_apache_request_headers)
54-
ZEND_FALIAS(getallheaders, frankenphp_request_headers, arginfo_getallheaders)
57+
ZEND_RAW_FENTRY("apache_request_headers", zif_frankenphp_request_headers, arginfo_apache_request_headers, 0, NULL, NULL)
58+
ZEND_RAW_FENTRY("getallheaders", zif_frankenphp_request_headers, arginfo_getallheaders, 0, NULL, NULL)
5559
ZEND_FE(frankenphp_response_headers, arginfo_frankenphp_response_headers)
56-
ZEND_FALIAS(apache_response_headers, frankenphp_response_headers, arginfo_apache_response_headers)
60+
ZEND_RAW_FENTRY("apache_response_headers", zif_frankenphp_response_headers, arginfo_apache_response_headers, 0, NULL, NULL)
5761
ZEND_FE(mercure_publish, arginfo_mercure_publish)
62+
ZEND_FE(frankenphp_log_message, arginfo_frankenphp_log_message)
5863
ZEND_FE_END
5964
};

0 commit comments

Comments
 (0)