Commit Graph

63 Commits

Author SHA1 Message Date
Valentin Bartenev
10f90f0d48 Configuration: added checking for presence of mandatory fields. 2020-07-24 20:25:20 +03:00
Max Romanov
d3c8d62280 PHP: using nxt_unit_default_init() for module structure init.
Using this function in all language modules helps to avoid code duplication
and reduce the size of future patches.
2020-07-23 14:25:12 +03:00
Max Romanov
fa696569f9 PHP: removing assertion to fix build on macOS.
The nxt_assert macro uses nxt_thread_context, which caused the following linker
error when using it in the library:

ld: illegal thread local variable reference to regular symbol
_nxt_thread_context for architecture x86_64
2020-07-23 14:24:16 +03:00
Valentin Bartenev
d86e0a7aec PHP: logging in request context when possible. 2020-07-21 20:27:37 +03:00
Valentin Bartenev
f46ef1b121 PHP: fixed incorrect time in interpreter error log messages.
Previously, the log message callback used a generic log function, that relied on the process time cache.
Since there were no time update calls in the application processes, all log lines were printed with the
same time, usually correlated with the process start.

Now, a non-cached logging function from libunit is used.
2020-07-21 20:27:37 +03:00
Tiago Natel de Moura
e2b53e16c6 Added "rootfs" feature. 2020-05-28 14:57:41 +01:00
Tiago Natel de Moura
e9e5ddd5a5 Refactor of process management.
The process abstraction has changed to:

  setup(task, process)
  start(task, process_data)
  prefork(task, process, mp)

The prefork() occurs in the main process right before fork.

The file src/nxt_main_process.c is completely free of process
specific logic.

The creation of a process now supports a PROCESS_CREATED state.  The
The setup() function of each process can set its state to either
created or ready.  If created, a MSG_PROCESS_CREATED is sent to main
process, where external setup can be done (required for rootfs under
container).

The core processes (discovery, controller and router) doesn't need
external setup, then they all proceeds to their start() function
straight away.

In the case of applications, the load of the module happens at the
process setup() time and The module's init() function has changed
to be the start() of the process.

The module API has changed to:

  setup(task, process, conf)
  start(task, data)

As a direct benefit of the PROCESS_CREATED message, the clone(2) of
processes using pid namespaces now doesn't need to create a pipe
to make the child block until parent setup uid/gid mappings nor it
needs to receive the child pid.
2020-03-09 16:28:25 +00:00
Remi Collet
140b81208e PHP: building with PHP 8 (development version). 2020-05-20 11:18:03 +03:00
Valentin Bartenev
376d758dd7 PHP: implemented "targets" option.
This allows to specify multiple subsequent targets inside PHP applications.
For example:

  {
      "listeners": {
          "*:80": {
              "pass": "routes"
          }
      },

      "routes": [
          {
              "match": {
                  "uri": "/info"
              },

              "action": {
                  "pass": "applications/my_app/phpinfo"
              }
          },
          {
              "match": {
                  "uri": "/hello"
              },

              "action": {
                  "pass": "applications/my_app/hello"
              }
          },
          {
              "action": {
                  "pass": "applications/my_app/rest"
              }
          }
      ],

      "applications": {
          "my_app": {
              "type": "php",
              "targets": {
                  "phpinfo": {
                      "script": "phpinfo.php",
                      "root": "/www/data/admin",
                  },

                  "hello": {
                      "script": "hello.php",
                      "root": "/www/data/test",
                  },

                  "rest": {
                      "root": "/www/data/example.com",
                      "index": "index.php"
                  },
              }
          }
      }
  }
2020-05-14 13:15:01 +03:00
Tiago Natel de Moura
36578c7b43 PHP: fixed log format in alert.
Found by Coverity: CID 354832 and CID 354833.
2020-03-04 13:42:08 +00:00
Tiago Natel de Moura
f99d20ad39 PHP: optimization to avoid surplus chdir(2) calls.
For each request, the worker calls the php_execute_script function
from libphp that changes to the script directory before doing its
work and then restores the process directory before returning.  The
chdir(2) calls it performs are unnecessary in Unit design.  In simple
benchmarks, profiling shows that the chdir syscall code path (syscall,
FS walk, etc.) is where the CPU spends most of its time.

PHP SAPI semantics requires the script to be run from the script
directory.  In Unit's PHP implementation, we have two use cases:

- script
- arbitrary path

The "script" configuration doesn't have much need for a working
directory change: it can be changed once at module initialization.
The module needs to chdir again only if the user's PHP script also
calls chdir to switch to another directory during execution.

If "script" is not used in Unit configuration, we must ensure the
script is run from its directory (thus calling chdir before exec),
but there's no need to restore the working directory later.

Our implementation disables mandatory chdir calls with the SAPI
option SAPI_OPTION_NO_CHDIR, instead calling chdir only when needed.

To detect the user's calls to chdir, a simple "unit" extension is
added that hooks the built-in chdir() PHP call.
2020-03-03 14:38:08 +00:00
Tiago Natel de Moura
98c0ce6cc4 PHP: fixed php >= 7.4 with zts enabled. 2020-02-25 15:55:31 +00:00
Valentin Bartenev
f860c20a96 PHP: added check for the ".php" extension.
A check for the ".php" extension is added to prevent execution of files
with arbitrary extensions in cases where "index" and "script" options
aren't used.
2020-01-28 19:18:26 +03:00
Max Romanov
64f649f990 Adding "limits/shm" configuration validation and parsing. 2019-12-24 18:04:09 +03:00
Sergey Kandaurov
c416933171 PHP: zeroing the whole file_handle structure.
Fixes segfaults with PHP 7.4.
2019-09-23 11:56:31 +00:00
Valentin Bartenev
ef89815f03 PHP: fixed script filename setting, broken after 2a71417d297f. 2019-07-16 17:58:48 +03:00
Max Romanov
cc578b2e63 PHP: added PATH_INFO support. 2019-07-05 21:10:01 +03:00
Valentin Bartenev
924165c90b PHP: improved response status code handling.
There's no reason to parse "http_status_line"; the PHP interpreter already
does this.  If the line contains a valid status code, it's assigned to
"http_response_code".

This also fixes invalid status line handling, where the nxt_int_parse()
function returned -1; it was cast to unsigned, yielding response code 65535.
2019-07-05 18:42:30 +03:00
Max Romanov
b1ee073707 PHP: removing excessive debug message. 2019-06-28 12:20:00 +03:00
Max Romanov
452ce0789e Adjusting request schema value according to connection tls state.
This closes #223 issue on GitHub.
2019-03-21 13:55:57 +03:00
Andrey Zelenkov
22de5fcddf Style. 2019-03-11 17:31:59 +03:00
Valentin Bartenev
a5dd0f8aa9 Made QUERY_STRING mandatory.
According to CGI/1.1 RFC 3875:

   The server MUST set this variable; if the Script-URI does not include a
   query component, the QUERY_STRING MUST be defined as an empty string ("").

Python's PEP 333(3) allows omitting it in WSGI interface; PHP docs force no
requirements; PSGI and Rack specifications require it even if empty.

When nginx proxies requests over FastCGI, it always provides QUERY_STRING.
and some PHP apps have been observed to fail if it is missing (see issue
#201 on GitHub).

A drawback of this change (besides a small overhead) is that there will be
no easy way to tell a missing query string from an empty one (i.e. requests
with or without the "?" character); yet, it's negligible compared to the
possible benefits of wider application compatibility.

This closes #226 issue on GitHub.
2019-02-28 20:20:41 +03:00
Max Romanov
5bfdebb9e4 Introducing Java Servlet Container beta. 2019-02-28 18:02:42 +03:00
Valentin Bartenev
e929d08201 Fixed processing of SERVER_NAME after 77aad2c142a0.
Previously, the nxt_router_prepare_msg() function expected server host among
other headers unmodified.  It's not true anymore since normalization of the
Host header has been introduced in 77aad2c142a0.

The nxt_unit_split_host() function was removed.  It didn't work correctly with
IPv6 literals.  Anyway, after 77aad2c142a0 the port splitting is done in router
while Host header processing.
2019-02-27 17:25:07 +03:00
Valentin Bartenev
db63191719 PHP: fixed "disable_functions" and "disable_classes" options.
It turned out they need additional processing to work.
This closes #183 issue on GitHub.
2018-11-27 22:06:39 +03:00
Valentin Bartenev
262578dc71 PHP: workaround for bug #71041.
Since PHP 7, a zend_signal_startup() call is required if the interpreter
was built with ZEND_SIGNALS defined; such a call was added in 3fd76e4ce70a.

However, the zend_signal_startup() export is missing from the PHP library;
as the result, dlopen() fails with the 'Undefined symbol "zend_signal_startup"'
error while loading the PHP module.

Meanwhile, if PHP is built without ZTS, the zend_signal_startup() call can
be omitted; otherwise, the missing call causes segmentation fault.

The PHP fix already was committed to upstream, but we still have to deal
with numerous unpatched versions remaining at large.

See the related PHP bug: https://bugs.php.net/bug.php?id=71041
2018-11-22 20:23:43 +03:00
Valentin Bartenev
adf22b6a0d PHP: fixed compatibility with ZTS.
This closes #184 issue on GitHub.
2018-11-21 18:22:19 +03:00
Max Romanov
1bb22d1e92 Unit application library.
Library now used in all language modules.
Old 'nxt_app_*' code removed.

See src/test/nxt_unit_app_test.c for usage sample.
2018-08-06 17:27:33 +03:00
Valentin Bartenev
7e3de003c7 PHP: fixed request body processing.
The implementation of module was based on the assumption that PHP reads request
body and headers in the particular order.  For the POST request the body goes
before headers and vice versa for all other requests.

But as it appeared later, this order is unspecified and depends on many factors,
including the particular code of PHP application.  Among other factors those
can affect ordering:

 - presence of "Content-Type" header;
 - "variables_order" php.ini setting;
 - "enable_post_data_reading" php.ini setting;
 - reading php://input by application;

and this list can be incomplete.

As a temporary workaround, request body now is always put before headers and it
is gracefully skipped whenever PHP wants to get headers.

This closes #144 issue on GitHub.
2018-07-05 16:43:45 +03:00
Valentin Bartenev
234deb51f4 PHP: fixed setting of individual configuration options.
The previous method changed PHP options only for the first request.
On the request completion the options were rolled back.

This closes #145 issue on GitHub.
2018-07-03 17:12:47 +03:00
Igor Sysoev
50228b35b6 Removed usage of nxt_thread_context in loadable modules.
This change allows to use __thread class storage on MacOSX.
2018-06-28 18:31:13 +03:00
Valentin Bartenev
1a52d876f7 Introduced nxt_length() macro. 2018-06-25 16:51:47 +03:00
Valentin Bartenev
8f278a5fed PHP: added setting of individual configuration options. 2018-06-07 16:17:32 +03:00
Valentin Bartenev
388390888b PHP: added setting of php.ini configuration file path. 2018-06-07 16:17:31 +03:00
Valentin Bartenev
3e8dbfe5ff Added SERVER_SOFTWARE request meta-variable. 2018-05-21 16:14:24 +03:00
Valentin Bartenev
d15b4ca906 Style. 2018-04-05 15:49:41 +03:00
Alexander Borisov
49bd3a21e0 Changed version processing for modules. 2018-04-04 18:53:39 +03:00
Valentin Bartenev
e254eecb77 PHP: fixed segfault on initialization.
PHP SAPI can call log handler while initializing.  Particularly, that happens
if there's a problem in loading some extension specified in php.ini file.
On this stage server context is empty, so now nxt_thread_log_error() is used.
2018-03-16 18:19:48 +03:00
Valentin Bartenev
912a49c609 Reduced number of critical log levels. 2018-03-05 17:32:50 +03:00
Max Romanov
fa49d042a8 PHP: Terminating names with zero.
Fixing issue introduced in changeset 462:17a2c9b27b57 .
2018-01-12 16:37:42 +03:00
Max Romanov
aad4229cbc Initializing script_name.start before using.
This makes gcc 4.4.6 happy.
2018-01-12 11:19:00 +03:00
Max Romanov
349717fb90 Changing relative php scripts paths to real ones.
This is required to run phpMyAdmin.
2018-01-11 22:14:20 +03:00
Igor Sysoev
8492ba945b Fixed Go package and PHP module building.
Go package and PHP module could not be built after changeset 5817734dd9b9.
2017-12-28 21:07:28 +03:00
Igor Sysoev
9a6d3c5775 HTTP keep-alive connections support. 2017-12-28 16:01:06 +03:00
Max Romanov
be36cf52c8 Introducing application 'atexit' hook.
Finalizing Python interpreter.

This closes #65 issue on GitHub.
2017-12-27 14:02:11 +03:00
Igor Sysoev
3c6edead25 Added the debug option to module compatibility vector. 2017-10-18 18:05:51 +03:00
Max Romanov
d87a4fb642 Moving body data before headers for PHP POST.
PHP SAPI tries to read body for POST request before registering
header-specific variables. For other methods, read_post_body() called by SAPI
after variables registration.

This closes #10 issue on GitHub.
2017-09-07 16:39:31 -07:00
Igor Sysoev
58907888e5 Style fixes. 2017-09-06 02:30:55 +03:00
Igor Sysoev
ff515f4312 Added SERVER_ADDR parameter for Python and PHP modules. 2017-09-01 07:54:01 +03:00
Sergey Kandaurov
f27ed60a09 PHP SAPI: typo fixed. 2017-08-31 15:16:18 +03:00