Skip to content

Commit

Permalink
Merge pull request #307 from krakjoe/florian/request_info_in_threads
Browse files Browse the repository at this point in the history
Make `request_info` from SAPI globals accessible in threads
  • Loading branch information
realFlowControl authored Jul 22, 2024
2 parents 0296dd9 + 46a8173 commit ebd810d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ zend_object* php_parallel_runtime_create(zend_class_entry *type) {
php_parallel_scheduler_init(runtime);

runtime->parent.server = SG(server_context);
runtime->parent.request_info = &SG(request_info);

return &runtime->std;
}
Expand Down
3 changes: 3 additions & 0 deletions src/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
| Author: krakjoe |
+----------------------------------------------------------------------+
*/
#include "SAPI.h"

#ifndef HAVE_PARALLEL_RUNTIME_H
#define HAVE_PARALLEL_RUNTIME_H

Expand All @@ -32,6 +34,7 @@ typedef struct _php_parallel_runtime_t {
} child;
struct {
void *server;
sapi_request_info *request_info;
} parent;
zend_llist schedule;
zend_object std;
Expand Down
1 change: 1 addition & 0 deletions src/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ static zend_always_inline php_parallel_runtime_t* php_parallel_scheduler_setup(p
TSRMLS_CACHE_UPDATE();

SG(server_context) = runtime->parent.server;
SG(request_info) = *runtime->parent.request_info;

runtime->child.interrupt = &EG(vm_interrupt);

Expand Down
18 changes: 18 additions & 0 deletions tests/base/070.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
SAPI globals
--SKIPIF--
<?php
if (!extension_loaded('parallel')) {
die("skip parallel not loaded");
}
?>
--FILE--
<?php
var_dump($_SERVER['argc']);
\parallel\run(function(){
var_dump($_SERVER['argc']);
});
?>
--EXPECT--
int(1)
int(1)

0 comments on commit ebd810d

Please sign in to comment.