Skip to content

Commit 8e172c5

Browse files
feat: add frankenphp_log_message() as a PHP function
1 parent 4e6d67e commit 8e172c5

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

frankenphp.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,19 @@ PHP_FUNCTION(headers_send) {
509509
RETURN_LONG(sapi_send_headers());
510510
}
511511

512+
PHP_FUNCTION(frankenphp_log_message) {
513+
char *message = NULL;
514+
size_t message_len = 0;
515+
zend_long level = 0;
516+
517+
ZEND_PARSE_PARAMETERS_START(2, 2)
518+
Z_PARAM_STRING(message, message_len)
519+
Z_PARAM_LONG(level)
520+
ZEND_PARSE_PARAMETERS_END();
521+
522+
go_log_n(message, message_len, (int)level);
523+
}
524+
512525
PHP_MINIT_FUNCTION(frankenphp) {
513526
zend_function *func;
514527

frankenphp.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,16 @@ func go_read_cookies(threadIndex C.uintptr_t) *C.char {
575575
//export go_log
576576
func go_log(message *C.char, level C.int) {
577577
m := C.GoString(message)
578+
phpLog(m, level)
579+
}
580+
581+
//export go_log_n
582+
func go_log_n(message *C.char, len C.int, level C.int) {
583+
m := C.GoStringN(message, len)
584+
phpLog(m, level)
585+
}
578586

587+
func phpLog(m string, level C.int) {
579588
var le syslogLevel
580589
if level < C.int(syslogLevelEmerg) || level > C.int(syslogLevelDebug) {
581590
le = syslogLevelInfo

frankenphp.stub.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ function frankenphp_response_headers(): array|bool {}
3232
*/
3333
function apache_response_headers(): array|bool {}
3434

35+
function frankenphp_log_message(str $message, int $level): void {}

frankenphp_arginfo.h

Lines changed: 9 additions & 1 deletion
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: 05ebde17137c559e891362fba6524fad1e0a2dfe */
2+
* Stub hash: fc711594a88d4fc3d1c1af0274c3c15ec1f3d733 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_frankenphp_handle_request, 0, 1,
55
_IS_BOOL, 0)
@@ -30,11 +30,18 @@ ZEND_END_ARG_INFO()
3030

3131
#define arginfo_apache_response_headers arginfo_frankenphp_response_headers
3232

33+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_frankenphp_log_message, 0, 2,
34+
IS_VOID, 0)
35+
ZEND_ARG_OBJ_INFO(0, message, str, 0)
36+
ZEND_ARG_TYPE_INFO(0, level, IS_LONG, 0)
37+
ZEND_END_ARG_INFO()
38+
3339
ZEND_FUNCTION(frankenphp_handle_request);
3440
ZEND_FUNCTION(headers_send);
3541
ZEND_FUNCTION(frankenphp_finish_request);
3642
ZEND_FUNCTION(frankenphp_request_headers);
3743
ZEND_FUNCTION(frankenphp_response_headers);
44+
ZEND_FUNCTION(frankenphp_log_message);
3845

3946
// clang-format off
4047
static const zend_function_entry ext_functions[] = {
@@ -47,6 +54,7 @@ static const zend_function_entry ext_functions[] = {
4754
ZEND_FALIAS(getallheaders, frankenphp_request_headers, arginfo_getallheaders)
4855
ZEND_FE(frankenphp_response_headers, arginfo_frankenphp_response_headers)
4956
ZEND_FALIAS(apache_response_headers, frankenphp_response_headers, arginfo_apache_response_headers)
57+
ZEND_FE(frankenphp_log_message, arginfo_frankenphp_log_message)
5058
ZEND_FE_END
5159
};
5260
// clang-format on

0 commit comments

Comments
 (0)