Skip to content

Commit 6cec2d9

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

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

frankenphp.c

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

512+
static void frankenphp_log_message(const char *message, int syslog_type_int) {
513+
go_log((char *)message, syslog_type_int);
514+
}
515+
516+
PHP_FUNCTION(frankenphp_log_message) {
517+
char *message = NULL;
518+
size_t message_len = 0;
519+
zend_long level = 0;
520+
521+
ZEND_PARSE_PARAMETERS_START(2, 2)
522+
Z_PARAM_STRING(message, message_len)
523+
Z_PARAM_LONG(level)
524+
ZEND_PARSE_PARAMETERS_END();
525+
526+
frankenphp_log_message(message, (int)level);
527+
}
528+
512529
PHP_MINIT_FUNCTION(frankenphp) {
513530
zend_function *func;
514531

@@ -801,10 +818,6 @@ static void frankenphp_register_variables(zval *track_vars_array) {
801818
go_register_variables(thread_index, track_vars_array);
802819
}
803820

804-
static void frankenphp_log_message(const char *message, int syslog_type_int) {
805-
go_log((char *)message, syslog_type_int);
806-
}
807-
808821
static char *frankenphp_getenv(const char *name, size_t name_len) {
809822
struct go_getenv_return result = go_getenv(thread_index, (char *)name);
810823

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)