Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions sapi/apache2handler/php_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,49 @@ PHP_FUNCTION(apache_response_headers)
}
/* }}} */

/* {{{ The allows for direct select calls on Apache's connection socket */
PHP_FUNCTION(apache_connection_stream)
{
php_struct *ctx = SG(server_context);
request_rec *r;
apr_socket_t *apr_sock;
int fd;
php_stream *stream;

ZEND_PARSE_PARAMETERS_NONE();

if (!ctx) {
php_error_docref(NULL, E_WARNING, "Server context is not available");
RETURN_FALSE;
}

r = ctx->r;
if (!r) {
php_error_docref(NULL, E_WARNING, "Request record is not available");
RETURN_FALSE;
}

apr_sock = ap_get_conn_socket(r->connection);
if (!apr_sock) {
php_error_docref(NULL, E_WARNING, "Failed to obtain connection socket");
RETURN_FALSE;
}

if (apr_os_sock_get(&fd, apr_sock) != APR_SUCCESS) {
php_error_docref(NULL, E_WARNING, "Failed to get native socket descriptor");
RETURN_FALSE;
}

stream = php_stream_sock_open_from_socket(fd, NULL);
if (!stream) {
php_error_docref(NULL, E_WARNING, "Failed to open stream from socket");
RETURN_FALSE;
}

php_stream_to_zval(stream, return_value);
}
/* }}} */

/* {{{ Get and set Apache request notes */
PHP_FUNCTION(apache_note)
{
Expand Down
2 changes: 2 additions & 0 deletions sapi/apache2handler/php_functions_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions sapi/cli/php_cli_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,28 @@ PHP_FUNCTION(apache_response_headers) /* {{{ */
}
/* }}} */

PHP_FUNCTION(apache_connection_stream) /* {{{ */
{
php_cli_server_client *client = SG(server_context);
php_stream *stream;

ZEND_PARSE_PARAMETERS_NONE();

if (!client) {
php_error_docref(NULL, E_WARNING, "Server context is not available");
RETURN_FALSE;
}

stream = php_stream_sock_open_from_socket(client->sock, NULL);
if (!stream) {
php_error_docref(NULL, E_WARNING, "Failed to open stream from socket in cli server");
RETURN_FALSE;
}

php_stream_to_zval(stream, return_value);
}
/* }}} */

/* {{{ cli_server module */

static void cli_server_init_globals(zend_cli_server_globals *cg)
Expand Down Expand Up @@ -495,6 +517,7 @@ const zend_function_entry server_additional_functions[] = {
PHP_FE(cli_get_process_title, arginfo_cli_get_process_title)
PHP_FE(apache_request_headers, arginfo_apache_request_headers)
PHP_FE(apache_response_headers, arginfo_apache_response_headers)
PHP_FE(apache_connection_stream, NULL)
PHP_FALIAS(getallheaders, apache_request_headers, arginfo_getallheaders)
PHP_FE_END
};
Expand Down
Loading