You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Provides thread safety for running multiple PHP environments in parallel.
86
+
87
+
#### zend_signal_startup (Signal Handling)
88
+
89
+
Defines globally how PHP should handle signals, not configurable with SAPI.
90
+
91
+
#### sapi_startup (Server API)
92
+
93
+
Initializes the SAPI, and provides a way to configure it. This is really just
94
+
a container for loading INI settings, extensions, and allocating space for
95
+
superglobals on the current thread.
96
+
97
+
#### php_embed_module.startup
98
+
99
+
This is the only actually _configurable_ part of SAPI. It treats the
100
+
PHP server you're trying to construct as just another a module/extension,
101
+
which is a bit odd as the thing that is supposed to be orchestrating
102
+
everything.
103
+
104
+
Configuration of this stages is done through [one-big-struct](https://github.com/php/php-src/blob/6024122e54f4e8a4f35c0abe9b46425856a11e6c/main/SAPI.h#L237-L290)
105
+
which contains individual functions for:
106
+
107
+
- reading POST data to populate `$_POST`
108
+
- reading GET data to populate `$_GET`
109
+
- reading cookies to populate `$_COOKIE`
110
+
- reading environment variables to populate `$_ENV`
111
+
- reading request headers to populate `$_SERVER`
112
+
- reading request body to populate `php://input`
113
+
- writing response headers
114
+
- writing response body from `php://output`
115
+
- Handling errors
116
+
117
+
#### php_request_startup (Request Startup)
118
+
119
+
This is the scope in which the actual request can occur. It allocates space
120
+
for the request-related superglobals, and sets up the request environment.
121
+
Within this scope PHP code can then be run with those request-specific
122
+
superglobals populated.
123
+
124
+
Within SAPI this stage is bundled into the startup of the entire SAPI system,
125
+
and so a SAPI construction can only handle a single request before tearing down
126
+
everything completely.
127
+
128
+
The _better_ way is to reuse this stage and then probably construct a separate
129
+
php_embed_module also for each request. In this way most of the PHP environment
130
+
can be shared between requests, and only the request-specific data needs to be
131
+
updated.
132
+
133
+
### Maybe PHP can also be concurrent?
134
+
135
+
PHP is designed to allow an environment to be shared across multiple threads
136
+
with the `tsrm` system. But as input and output are _streams_ it may also be
137
+
possible to run multiple requests on the same thread concurrently, to some
138
+
extent, by switching out their superglobal states whenever stream data would
139
+
be read, or when writing out would block the current request.
140
+
141
+
A caveat here is that _other_ than the input and output streams, things are
142
+
generally synchronous. For example, typical database drivers would block the
143
+
thread. Being _partially_ async may still be an improvement though, and there's
144
+
always the possibility of us writing our own async components, which would get
145
+
us better performance while also possibly locking in our users a bit more.
Provides thread safety for running multiple PHP environments in parallel.
166
-
167
-
#### zend_signal_startup (Signal Handling)
168
-
169
-
Defines globally how PHP should handle signals, not configurable with SAPI.
170
-
171
-
#### sapi_startup (Server API)
172
-
173
-
Initializes the SAPI, and provides a way to configure it. This is really just
174
-
a container for loading INI settings, extensions, and allocating space for
175
-
superglobals on the current thread.
176
-
177
-
#### php_embed_module.startup
178
-
179
-
This is the only actually _configurable_ part of SAPI. It treats the
180
-
PHP server you're trying to construct as just another a module/extension,
181
-
which is a bit odd as the thing that is supposed to be orchestrating
182
-
everything.
183
-
184
-
Configuration of this stages is done through [one-big-struct](https://github.com/php/php-src/blob/6024122e54f4e8a4f35c0abe9b46425856a11e6c/main/SAPI.h#L237-L290)
185
-
which contains individual functions for:
186
-
187
-
- reading POST data to populate `$_POST`
188
-
- reading GET data to populate `$_GET`
189
-
- reading cookies to populate `$_COOKIE`
190
-
- reading environment variables to populate `$_ENV`
191
-
- reading request headers to populate `$_SERVER`
192
-
- reading request body to populate `php://input`
193
-
- writing response headers
194
-
- writing response body from `php://output`
195
-
- Handling errors
196
-
197
-
#### php_request_startup (Request Startup)
198
-
199
-
This is the scope in which the actual request can occur. It allocates space
200
-
for the request-related superglobals, and sets up the request environment.
201
-
Within this scope PHP code can then be run with those request-specific
202
-
superglobals populated.
203
-
204
-
Within SAPI this stage is bundled into the startup of the entire SAPI system,
205
-
and so a SAPI construction can only handle a single request before tearing down
206
-
everything completely.
207
-
208
-
The _better_ way is to reuse this stage and the probably construct a separate
209
-
php_embed_module also for each request. In this way most of the PHP environment
210
-
can be shared between requests, and only the request-specific data needs to be
211
-
updated.
212
-
213
-
### Maybe PHP can also be concurrent?
214
-
215
-
PHP is designed to allow an environment to be shared across multiple threads
216
-
with the `tsrm` system. But as input and output are _streams_ it may also be
217
-
possible to run multiple requests on the same thread concurrently, to some
218
-
extent, by switching out their superglobal states whenever stream data would
219
-
be read, or when writing out would block the current request.
220
-
221
-
A caveat here is that _other_ than the input and output streams, things are
222
-
generally synchronous. For example, typical database drivers would block the
223
-
thread. Being _partially_ async may still be an improvement though, and there's
224
-
always the possibility of us writing our own async components, which would get
225
-
us better performance while also possibly locking in our users a bit more.
0 commit comments