Commit graph

446 commits

Author SHA1 Message Date
Tim Düsterhus
057ff3519d
sapi/cli: Print non-default INI settings for --ini=diff (#17762)
This is a follow-up for php/php-src#17459, updating the command-line flag to
not modify the behavior of `--ini`.
2025-03-04 08:42:06 +01:00
Niels Dossche
98e0501343
Drop support for -z CLI/CGI option
This functionality didn't actually work.
This was discussed on the mailing list [1] and no one objected.

[1] https://externals.io/message/126368

Closes GH-17883.
2025-03-03 08:21:56 +01:00
Christoph M. Becker
650086f3e6
Exclude unused functions from compilation units (GH-17686)
This avoids Clang complaining with `-Wunused-function`.

We also introduce the macro `PRELOAD_SUPPORT` for clarification.
2025-02-10 18:00:19 +01:00
Tim Düsterhus
e3798c2ab9
sapi/cli: Extend --ini to print INI settings changed from the builtin default (#17459)
* sapi/cli: Extend `--ini` to print INI settings changed from the builtin default

This is intended to make it easier to check whether or not a given INI setting
is changed from the default when building reproducers for a bugreport, without
forgetting any that might be relevant to the report.

As an example, running `sapi/cli/php -c /etc/php/8.3/cli/ --ini` on my Ubuntu
will now output:

    Configuration File (php.ini) Path: /usr/local/lib
    Loaded Configuration File:         /etc/php/8.3/cli/php.ini
    Scan for additional .ini files in: (none)
    Additional .ini files parsed:      (none)

    Non-standard INI settings:
    allow_url_include: "0" -> ""
    auto_append_file: (none) -> ""
    auto_prepend_file: (none) -> ""
    display_errors: "1" -> ""
    display_startup_errors: "1" -> ""
    enable_dl: "1" -> ""
    error_reporting: (none) -> "22527"
    html_errors: "1" -> "0"
    ignore_repeated_errors: "0" -> ""
    ignore_repeated_source: "0" -> ""
    implicit_flush: "0" -> "1"
    log_errors: "0" -> "1"
    mail.add_x_header: "0" -> ""
    mail.mixed_lf_and_crlf: "0" -> ""
    max_execution_time: "30" -> "0"
    memory_limit: "128M" -> "-1"
    request_order: (none) -> "GP"
    session.cookie_httponly: "0" -> ""
    session.gc_divisor: "100" -> "1000"
    session.gc_probability: "1" -> "0"
    session.sid_bits_per_character: "4" -> "5"
    session.sid_length: "32" -> "26"
    short_open_tag: "1" -> ""
    unserialize_callback_func: (none) -> ""
    user_dir: (none) -> ""
    variables_order: "EGPCS" -> "GPCS"
    zend.assertions: "1" -> "-1"
    zend.exception_ignore_args: "0" -> "1"
    zend.exception_string_param_max_len: "15" -> "0"

* Improve phrasing

Co-authored-by: Michael Voříšek <mvorisek@mvorisek.cz>

* NEWS/UPGRADING

---------

Co-authored-by: Michael Voříšek <mvorisek@mvorisek.cz>
2025-02-05 17:54:52 +01:00
Christoph M. Becker
107bd080a5
Fix Clang style nits (GH-17685)
This addresses all `-Wlogical-op-parentheses` and `-Wmissing-braces`
warnings across the whole code base (all Windows specific code).
2025-02-05 14:13:56 +01:00
Ilija Tovilo
0ad6e4efb0
[skip ci] Document --repeat flag as internal (GH-16698)
Co-authored-by: Christoph M. Becker <cmbecker69@gmx.de>
2024-11-04 17:40:08 +01:00
Gina Peter Banyard
6ddab74d55
sapi: Fix some variable shadowing (#16485)
sapi_module, mime_type_map, zend_extensions, php_cgi_globals, and phpdbg_globals are true globals which are being shadowed
2024-10-17 22:46:23 +01:00
Ilija Tovilo
bc07a8a28a
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix printing backtrace of fake generator frame
2024-09-27 17:37:07 +02:00
Ilija Tovilo
8c556b211d
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix printing backtrace of fake generator frame
2024-09-27 17:35:55 +02:00
Ilija Tovilo
706bcdbc1a
Fix printing backtrace of fake generator frame
Fixes GH-15851
Closes GH-15952
2024-09-27 17:34:51 +02:00
Peter Kokot
e016e3521a
Remove redundant HAVE_LIBREADLINE check (#15623)
The HAVE_LIBREADLINE is at this point only defined by Autotools and this
check is for Windows only where only HAVE_LIBEDIT is defined.
2024-08-29 12:49:34 +02:00
Calvin Buckley
afc5738154
Show build provider and unify version information printing (#14657)
* Show build provider information in "php -v"

Vendors such as distributions can set the `PHP_BUILD_PROVIDER`
variable, that gets printed in phpinfo. However, I find that users check
`php -v` more often than phpinfo to see what PHP they're running. The
problem with this is that it does not show that build provider
information.

This change makes the build provider information printed on an
additional line of the version information.

* Put on same line so it works with or without env var

Unbreaks build without PHP_BUILD_PROVIDER set.

* change wording in provider version text

better grammatically; many different possibilities here though

* Unify SAPI version printing

This makes it so that all of the SAPIs share the same code for printing
version information. This is useful in case of any future changes to the
version information, such as i.e. adding build provider to the output.

* Make include for php_print_version explicit

* Preserve phpdbg version and output channel

php_printf doesn't have same semantics, as phpdbg_out could be on a
different output than stdout/err. Also add the phpdbg version (in case
it differs from PHP's, to keep similar output before this PR)

* remove size variables

we don't use them and CI doesn't like unused variables

* Fix format string insecurity
2024-08-12 23:24:41 -03:00
lwlinux
15470bd16c
sapi/cli/php_cli.c: fix typos (#15057) 2024-07-22 06:41:02 +01:00
Peter Kokot
61a0e3bd19
Sync HAVE_OPENSSL* symbols (#14333)
This syncs few inconsistencies between the Windows and Autotools build
systems:
- HAVE_OPENSSL_EXT is now defined in the same style on both systems
  (undefined - extension is not available, defined to 1 - extension is
  available)
- HAVE_OPENSSL removed as it was only defined on Windows
2024-06-11 19:18:19 +02:00
Tim Düsterhus
10a6f0bd92
cli: Clean up formatting in do_cli() (#14531)
* cli: Add spaces around operators in do_cli()

* cli: Unify `switch()` body indentation in `do_cli()`
2024-06-10 15:12:05 +02:00
Tim Düsterhus
bca0c08408
Make the CLI mode available via the SAPI globals (#14479)
* Remove tautologically false condition in php_cli.c

* Make the CLI mode available via the SAPI globals

When hooking into RINIT it is currently pretty much impossible to determine
whether a file will actually be executed or if it just will be linted,
highlighted, or comments stripped: The startup is identical for all of them and
the chosen mode is not currently exposed to other extensions.

The `SG(server_context)` is currently entirely unused for the `cli` SAPI. It
appears to be appropriate to store the mode as a SAPI-specific information
inside of it.
2024-06-10 09:15:55 +02:00
Peter Kokot
c3388c1841
Sync #if/ifdef/defined (#14512)
These are either undefined or defined to 1:
- HAVE_LIBEDIT
- HAVE_LIBREADLINE
- ZEND_MAX_EXECUTION_TIMERS

Follow up of GH-5526 (-Wundef)
2024-06-10 08:56:10 +02:00
Peter Kokot
84a0da1574
Sync #if/ifdef/defined (#14508)
This syncs CPP macro conditions:
- _WIN32
- _WIN64
- HAVE_ALLOCA_H
- HAVE_ALPHASORT
- HAVE_ARPA_INET_H
- HAVE_CONFIG_H
- HAVE_DIRENT_H
- HAVE_DLFCN_H
- HAVE_GETTIMEOFDAY
- HAVE_LIBDL
- HAVE_POLL_H
- HAVE_PWD_H
- HAVE_SCANDIR
- HAVE_SYS_FILE_H
- HAVE_SYS_PARAM_H
- HAVE_SYS_SOCKET_H
- HAVE_SYS_TIME_H
- HAVE_SYS_TYPES_H
- HAVE_SYS_WAIT_H
- HAVE_UNISTD_H
- PHP_WIN32
- ZEND_WIN32

These are either undefined or defined to 1 in Autotools and Windows.

Follow up of GH-5526 (-Wundef).
2024-06-09 14:23:41 +02:00
Cristian Rodríguez
8e62e2b829
Mark multple functions as static (#13864)
* Mark many functions as static

Multiple functions are missing the static qualifier.

* remove unused struct sigactions

struct sigaction act, old_term, old_quit, old_int;
all unused.

* optimizer: minXOR and maxXOR are unused
2024-05-22 13:11:46 +02:00
Niels Dossche
a95d001a8a
Change calls to setmode to _setmode (#14220)
setmode is the deprecated alias of _setmode [1].

[1] https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/posix-setmode?view=msvc-170
2024-05-13 22:08:24 +02:00
Ilija Tovilo
1a0ef2c1cc
Revert "Remove name field from the zend_constant struct (#10954)"
This reverts commit f42992f580.

Closes GH-11604
2023-07-17 22:32:41 +02:00
Niels Dossche
f16b34f1d0 Implement GH-10024: support linting multiple files at once using php -l
This is supported in both the CLI and CGI modes. For CLI this required
little changes.

For CGI, the tricky part was that the options parsing happens inside the
loop. This means that options passed after the -l flag were previously
simply ignored. As we now re-enter the loop we would parse the options
again, and if they are handled but don't set the script name, then CGI
will think you want to read from standard in. To keep the same "don't
parse options" behaviour I simply wrapped the options handling inside an
if.

Closes GH-10024.
Closes GH-10710.
2023-07-05 15:20:36 +02:00
Ilija Tovilo
ad1b70d67e
Revert "Revert "Remove name field from the zend_constant struct (#10954)""
This reverts commit 9f4bd3040d.
2023-07-04 16:42:40 +02:00
Máté Kocsis
9f4bd3040d
Revert "Remove name field from the zend_constant struct (#10954)"
This reverts commit f42992f580.

Fix GH-11423
2023-07-03 15:16:24 +02:00
nielsdos
d8ee89d3fa Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix interrupted CLI output causing the process to exit
2023-06-23 17:43:01 +02:00
nielsdos
b9bf9ee2cb Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix interrupted CLI output causing the process to exit
2023-06-23 17:42:45 +02:00
nielsdos
1111a9517b Fix interrupted CLI output causing the process to exit
When writing the output in the CLI is interrupted by a signal, the
writing will fail in sapi_cli_single_write(), causing an exit later in
sapi_cli_ub_write(). This was the other part of the issue in GH-11498.
The solution is to restart the write if an EINTR has been observed.

Closes GH-11510.
2023-06-23 17:39:04 +02:00
George Peter Banyard
d5ad75108e
More usage of known zend_str instead of C string (#11381) 2023-06-08 13:03:29 +01:00
Niels Dossche
ac5920f92b Fix GH-11141: Could not open input file: should be sent to stderr
I grepped for php_printf cases in main/ and sapi/ and converted the
cases which clearly indicate errors to fprintf(stderr, ...), like
suggested in the linked issue.

Closes GH-11163.
2023-05-05 19:31:23 +02:00
nielsdos
f6c0c60ef6 Fix GH-11104: STDIN/STDOUT/STDERR is not available for CLI without a script
I found no reason why this is done this way.
Of course this will allow users to do stupid stuff like
`fclose(STDOUT);` etc. but if they type in that code they clearly know
what they're doing...

Close GH-11169.
2023-05-03 19:54:21 +02:00
Máté Kocsis
f42992f580
Remove name field from the zend_constant struct (#10954)
As global constant names are case-sensitive now, we don't have to store them separately above the constant table.
2023-04-03 22:13:47 +02:00
Niels Dossche
f247e48def
Remove always-false check in CLI (#10723)
This is the case c == 'i', so c == '?' is always false, hence the result
is always 0.
2023-02-28 12:24:09 +01:00
Christoph M. Becker
c8955c078a
Revert GH-10220
Cf. <https://github.com/php/php-src/pull/10220#issuecomment-1383739816>.

This reverts commit ecc880f491.
This reverts commit 588a07f737.
This reverts commit f377e15751.
This reverts commit b4ba16fe18.
This reverts commit 694ec1deea.
This reverts commit 6b34de8eba.
This reverts commit aa1cd02a43.
This reverts commit 308fd311ea.
This reverts commit 16203b53e1.
This reverts commit 738fb5ca54.
This reverts commit 9fdbefacd3.
This reverts commit cd4a7c1d90.
This reverts commit 928685eba2.
This reverts commit 01e5ffc85c.
2023-01-16 12:27:33 +01:00
Max Kellermann
6b34de8eba sapi/*: add missing includes 2023-01-10 14:19:03 +00:00
Jorg Adam Sowa
77ee92a50c
Remove unnecessary usage of CONST_CS
Closes GH-9685.
2022-11-28 17:12:07 +01:00
Jakub Zelenka
0a4a55fd44
Allow to not close stream on rscr dtor in php cli sapi 2022-07-18 10:58:50 +01:00
Arnaud Le Blanc
61ad0d9136 Fix build 2022-07-09 23:30:15 +02:00
Arnaud Le Blanc
da1cbd20c3 Merge branch 'PHP-8.1'
* PHP-8.1:
  [ci skip] NEWS
  Fix GH-8952: std streams can not be deliberately closed (#8953)
  intl extension, build fix for icu >= 69.x release. ubrk/ucnv_safeClone had been deprecated in favor of ubrk/ucnv_clone which does not use user provided stacks but remain thread safe.
2022-07-09 23:01:07 +02:00
Arnaud Le Blanc
2dbde18b29
Fix GH-8952: std streams can not be deliberately closed (#8953) 2022-07-09 22:58:02 +02:00
Christoph M. Becker
b8dee9b3fc
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix GH-8827: Intentionally closing std handles no longer possible
2022-06-20 18:04:34 +02:00
Christoph M. Becker
a8437d08a8
Fix GH-8827: Intentionally closing std handles no longer possible
We revert the commits which caused this regression from the PHP-8.0 and
PHP-8.1 branches for now.  We keep it in "master" because of PR #8833
which may offer a proper fix without BC break.
2022-06-20 18:01:02 +02:00
George Peter Banyard
5ba6ecd523
Minor refactoring of main/main.c and TSRM (#8608) 2022-05-24 08:34:55 +01:00
Levi Morrison
c53c3e200b Stop closing stderr and stdout streams (#8571)
Extensions may (and do) write to stderr in mshutdown and similar. In
the best case, with the stderr stream closed, it's just swallowed.

However, some libraries will do things like try to detect color, and
these will outright fail and cause an error path to be taken.
2022-05-20 13:41:02 +02:00
Arnaud Le Blanc
980385d12d Merge branch 'PHP-8.1'
* PHP-8.1:
  Stop closing stderr and stdout streams (#8570)
  Revert "XFAIL tests (GH-8588)"
  XFAIL tests (GH-8588)
  Stop closing stderr and stdout streams (#8569)
2022-05-20 13:40:27 +02:00
Levi Morrison
ffd27bdec4 Stop closing stderr and stdout streams (#8570)
Extensions may (and do) write to stderr in mshutdown and similar. In
the best case, with the stderr stream closed, it's just swallowed.

However, some libraries will do things like try to detect color, and
these will outright fail and cause an error path to be taken.
2022-05-20 13:40:09 +02:00
Arnaud Le Blanc
6465f3ed13 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  XFAIL tests (GH-8588)
  Stop closing stderr and stdout streams (#8569)
2022-05-20 13:36:22 +02:00
Levi Morrison
fa78e17724 Stop closing stderr and stdout streams (#8569)
Extensions may (and do) write to stderr in mshutdown and similar. In
the best case, with the stderr stream closed, it's just swallowed.

However, some libraries will do things like try to detect color, and
these will outright fail and cause an error path to be taken.
2022-05-20 13:27:23 +02:00
George Peter Banyard
9601475ebb
Minimal refactoring of CLI SAPI (#8519)
More specific types, some cleanup and voidifying functions which always return ``SUCCESS``
2022-05-09 22:29:16 +01:00
George Peter Banyard
b5db594fd2
Refacto php_module_startup() (#8303)
It only ever uses at most 1 additional modules
2022-04-27 23:07:11 +01:00
Max Kellermann
d87ba95acd
sapi/*: move duplicate "--define" code to library 2022-04-18 16:52:08 +02:00