Commit graph

59 commits

Author SHA1 Message Date
DannyS712
c1db64b808 Make use of ??= in more places
New feature from PHP 7.4

Change-Id: Ifa7a9bc7b2ec415ad7ecb23f4c1776f51f58fd6b
2022-12-17 01:10:13 +00:00
Umherirrender
ea5ea60b31 Various doc fixes about false on method arguments/return types
Doc-only changes

Change-Id: I5177f582ae7ee70c357e9389fed14819faf79463
2022-11-10 19:23:46 +00:00
jenkins-bot
a85966542d Merge "Use short array destructuring instead of list()" 2022-10-21 11:11:06 +00:00
Tim Starling
0077c5da15 Use short array destructuring instead of list()
Introduced in PHP 7.1. Because it's shorter and looks nice.

I used regex replacement.

Change-Id: I0555e199d126cd44501f859cb4589f8bd49694da
2022-10-21 15:33:37 +11:00
Tim Starling
43a93d9782 Use the null coalescing assignment operator
Available since PHP 7.4.

Automated search, manual replacement.

Change-Id: Ibb163141526e799bff08cfeb4037b52144bb39fa
2022-10-21 13:26:49 +11:00
Máté Szabó
36dd10f9de Migrate use of ${var}-style string interpolation
The "${var}" and "${expr}" style string interpolations are deprecated in
PHP 8.2. Migrate usages in core to "{$var}" as appropriate.

Bug: T314096
Change-Id: I269bad3d4a68c2b251b3e71a066289d4ad9fd496
2022-07-29 02:45:09 +02:00
jenkins-bot
6fad0d2888 Merge "phan: Upgrade mediawiki-phan-config to 0.11.1 and set minimum_target_php_version" 2022-03-29 17:17:13 +00:00
James D. Forrester
24e67e03b1 phan: Upgrade mediawiki-phan-config to 0.11.1 and set minimum_target_php_version
MediaWiki still supports PHP 7.2+, but we want to mainly test in newer versions
of PHP. Setting minimum_target_php_version to 7.2 this lets us run phan without
phan trying to get us to make PHP 7.2-incompatible changes to 'appease' PHP 8.0
or whatever later changes.

Some switches of generic 'resource' type-hinting to 'resource|object' to inform
phan to ignore this (triggering PHPCS at the time, ah well), rather than trying
to hint the specific novel PHP encapsulation classes to that have replaced them
from PHP 8.0 onwards but don't yet exist, and fixes from where we were checking
the results of implode and explode.

Bug: T293924
Change-Id: I629e3fb3adfad73beb3d424a07e643c2e079d9bb
2022-03-29 16:54:36 +00:00
Umherirrender
7aa0884029 phan: Remove PhanTypePossiblyInvalidDimOffset suppression
Make phan stricter about array keys
Remaining false positive issues are suppressed.
The suppression and the setting change can only be done together

Bug: T304887
Depends-On: I3105a5fd4826f8667b5232834defc5ec93be32a1
Depends-On: Ie9610a6e83731468311edb3ed17f80fc509de385
Change-Id: I701f12ab94478c3b8e7fd82110ade74a8e6b04ef
2022-03-28 23:26:49 +02:00
Aaron Schulz
cfbd854d05 http,objectcache: Use local-unaware floats in sprintf() calls
Bug: T303628
Change-Id: I7d92bc9dd2bc30711572abff36a0e1545c88479b
2022-03-24 14:59:03 +00:00
daniel
d599a54e5f HttpRequestFactory: allow 0 to mean no max timeout.
$wgHTTPMaxTimeout and $wgHTTPMaxConnectTimeout used to default to INF,
the positive infinity float value. This value has no representation in
JSON. In order to allow default configuration values to be defined in
a JsonSchema, we allow 0 to be used to represent "no limit" instead.

Bug: T294788
Change-Id: Id1b832b46ac6984655dcf0c06d5af7d356cca800
2022-01-28 18:40:03 +01:00
jenkins-bot
0519abd6d2 Merge "MultiHttpClient: Add note about PHP 8.0 support" 2022-01-26 23:47:23 +00:00
Tim Starling
6b5591be27 MultiHttpClient: Add note about PHP 8.0 support
Change-Id: Ib0b777eb7e5edc05ccf41c968ac814e1756d7cd9
2022-01-27 10:23:56 +11:00
jenkins-bot
99ebd44a00 Merge "Stop using is_resource() where possible" 2022-01-26 00:39:47 +00:00
Tim Starling
54c735354f Stop using is_resource() where possible
* Enforce the ban on is_resource in phpcs
* In OrderedStreamingForkController, the comment was incorrect. I
  confirmed using a small test script that if the child closes one end
  of a socket pair, the other end will still be open, and is_resource()
  will still return true, and fclose() will not fail. The issue was
  introduced in c82d30d19c, it was not present in the
  CirrusSearch copy of the class.
* Allow is_resource() for debug logging.
* Allow is_resource() for parameter validation where a stream may be
  passed to a function, since there is no alternative.

Bug: T260735
Change-Id: I59a752f7bb4b043ddfb2434b52a02f9221bf54db
2022-01-26 10:03:23 +11:00
Tim Starling
c96c1190bf Fix deprecation warning from CURLPIPE_HTTP1
Keep using pipelining as long as it is supported. Add covering test,
mostly to check for exceptions.

No need to set it to zero if the option is false, since zero is the
default.

Bug: T264735
Change-Id: I1a3873c27d2002a7374b98548a8c43065ea0d8ba
2022-01-25 14:35:41 +11:00
Kunal Mehta
12dbaa8638 Log headers in MultiHttpClient
These are useful when debugging requests that vary behavior based on
the headers specified, like Swift's x-copy-from. Additionally,
knowing the content-length is helpful when looking at how long
the request took.

We do know that some headers are likely to contain sensitive
passwords/tokens, so try to redact those ahead of time using a regex of:

 (authorization|auth|password|cookie)

This will catch the standard Authorization header, plus Swift's
X-Auth-Token and X-Auth-Key. The regex is a best effort, but not
intended to be fully comprehensive as there's already plenty of
private data being included in logs.

Change-Id: I6e695f357f92ce8d40b54ea39002fb7858f5596e
2021-11-29 22:57:37 +00:00
Kunal Mehta
5cadb281d6 MultiHttpClient: Check if $wgLocalHTTPProxy is false, not null
The default not configured value for $wgLocalHTTPProxy is false, not
null. So in MultiHttpClient make sure it defaults to false and check for
false when deciding whether to use the proxy.

MWHttpRequest already has the correct behavior.

Bug: T296312
Change-Id: I3962c24f9cb159fb7d1e194e59c8bef5261371c3
2021-11-23 10:17:50 -08:00
jenkins-bot
479cde3fca Merge "Support $wgLocalHTTPProxy in MultiHttpClient" 2021-11-22 21:36:42 +00:00
Reedy
7bf779524a Remove or replace usages of "sanity"
Bug: T254646
Change-Id: I2b120f0b9c9e1dc1a6c216bfefa3f2463efe1001
2021-11-19 23:19:42 +00:00
Kunal Mehta
f539b6f58c Support $wgLocalHTTPProxy in MultiHttpClient
This follows the same approach as MWHttpRequest, we inject
$wgLocalVirtualHosts, and for each request check whether it matches that
domain list, rewriting the request as necessary.

Unfortunately this requires a decent amount of code duplication because
MultiHttpClient is in includes/libs/ and can't depend on the same code
in MWHttpRequest.

Bug: T288848
Change-Id: Ia16d8f86b1cb20dde9fe487729d67d92af650cfe
2021-11-16 11:13:10 -08:00
Petr Pchelko
928f707731 Remove old HTTP request implementations
Since 1.34 setting non-default HTTP engine
has been deprecated. It's time to remove
the old implementations. Only Guzzle is
now available.

Change-Id: I978b75827e69db02cbc027fe0b89a028adfc6820
2021-11-08 07:04:06 -08:00
Alexandros Kosiaris
afe2d229c9 MultiHttpClient: Allow setting HTTP protocol version in curl
For context see T275752, but the premise is that we want to be able to
set the HTTP protocol version so that for specific use cases. That way
we will be able to use the proper protocol per use case, mitigating
potential future regressions or selectively rolling out a newer protocol
version per use case. Support setting CURLOPT_HTTP_VERSION, while making
sure to default to the current default which lets curl decide which
version to use

CurlHttpRequest already forcibly set this to 1.0 for what is worth

Bug: T275752
Change-Id: I82f4f174997ecaa54e33eb848b5f007c982506dd
2021-10-29 10:52:35 -07:00
Reedy
b1b6afd53f MultiHttpClient: Replace PHP version check with defined()
Bug: T285287
Change-Id: I3dfef3f0a13bc8a5ec54912976f23c0c497149a7
2021-06-23 01:47:59 +01:00
Umherirrender
78cc6d77ff build: Swap deprecated @codingStandardsIgnore to phpcs:ignore
Bug: T278594
Change-Id: I09a6175917090593e6e0055203a890c32bea03a5
2021-04-04 21:18:22 +02:00
Tim Starling
8bde51490a Swift HTTP client request log including timings
* Send Swift's MultiHttpClient logs to the FileOperation channel
* Add more detailed debugging information to those logs, including
  request execution time.

Bug: T276017
Change-Id: I221be1f452e03d19b7cd81430a9349a9db14f81f
2021-03-10 16:29:21 +11:00
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
jenkins-bot
320af70270 Merge "Make use of CURLMOPT_MAX_HOST_CONNECTIONS conditional on having curl >= 7.30.0" 2021-01-08 01:32:45 +00:00
Ammar Abdulhamid
fc26253cf6 http: Remove exception from MultiHttpClient for missing cURL
This is both dead code and if it works, it contradicts the fact that
cURL library is not officially required by MediaWiki.

The function existence has already been checked in self::isCurlEnabled()
so it should be presumed to exist here because the call is guarded
behind that check.

The class level doc also said if cURL is not available, requests will be
made serially, it does not say Exception will be thrown which will
effectively makes cURL a hard dependency for MediaWiki and makes the
serial request code useless.

Follows-up 0584339f5e (I2f9d4acbb49).

Change-Id: I7f172f177d7d17c80bb70b2fd6c67107f4340c21
2021-01-06 03:05:31 +00:00
Reedy
898ba5f607 Make use of CURLMOPT_MAX_HOST_CONNECTIONS conditional on having curl >= 7.30.0
Bug: T264986
Change-Id: I0a91eaf456d855b3f064bf5e4202bab1ced4a94c
2020-12-02 04:46:32 +00:00
Tim Starling
b2a8e26cda MultiHttpClient: Reduce the default timeout from 900 to 30
Per my caller survey in the linked bug, it is hard to find a caller
which actually needs a long timeout, but many callers used the default
timeout without reviewing it. The default was increased from 300 to 900
as a quick hack to fix T226979, but that has now been fixed by overriding
the timeout in SwiftFileBackend specifically.

Reduce the default to 30 since that is a more reasonable value to use when
serving web requests. Since everything that previously used this default
was migrated to use HttpRequestFactory::createMultiClient(), the timeout
for them was already reduced from 900 to 25 with no apparent ill
effects. This cleanup change should have no production impact.

Bug: T245170
Change-Id: Id6029afa4e3f1c6551cd823c3b0def01afcdc571
2020-06-15 15:34:13 +10:00
Umherirrender
aa83358172 Pass function name to HttpRequestFactory::create
Useful for logging

Change-Id: Ie1e3f2fefdf65cabd3fcca206e793091b99d3faa
2020-06-07 12:20:06 +00:00
Tim Starling
504fe2af11 Respect configured default HTTP timeouts, and introduce max timeouts
* Add HttpRequestFactory::createMultiClient(), which returns a
  MultiHttpClient with configured defaults applied. This is similar to
  the recently-deprecated Http::createMultiClient().
* Introduce $wgHTTPMaxTimeout and $wgHTTPMaxConnectTimeout which, if set
  to a lower value than their defaults of infinity, will limit the
  applied HTTP timeouts, whether configured or passed on a per-request
  basis. This is based on the frequently correct assumption that ops know
  more about timeouts than developers.
* In case developers believe, after becoming aware of this new situation,
  that they actually do know more about timeouts than ops, it is possible
  to override the configured maximum by passing similarly named options
  to HttpRequestFactory::createMultiClient() and
  HttpRequestFactory::create().
* Apply modern standards to HttpRequestFactory by injecting a logger and
  all configuration parameters used by its backends.
* As in Http, the new createMultiClient() will use a MediaWiki/1.35
  User-Agent and the 'http' channel for logging.
* Document that no proxy will be used for createMultiClient().
  Proxy config is weird and was previously a good reason to use
  MultiHttpClient over HttpRequestFactory.
* Deprecate direct construction of MWHttpRequest without a timeout
  parameter

Bug: T245170
Change-Id: I8252f6c854b98059f4916d5460ea71cf4b580149
2020-05-21 09:30:57 +10:00
Reedy
40e522747c Fix some includes/libs PSR12.Properties.ConstantVisibility.NotFound
Change-Id: I92e2cbf39d2851d215e8be456e86bb99524dea5f
2020-05-16 02:32:53 +01:00
James D. Forrester
1c24141991 MultiHttpClient: Also fallover to non-curl if curl_multi* is blocked
Requested by a user at https://www.mediawiki.org/wiki/Topic:Vkk1ahk3eggd9747 for
whom their hoster provides curl but with multi-threaded functions removed for
some reason.

Change-Id: Id3877c600ae02feffb67f74a815430f8e679230a
2020-04-27 14:43:38 -07:00
Daimona Eaytoy
41ee2f2c61 Upgrade phan to 0.9.1
Released just now.

Many old suppressions can now be removed. Enabling the issue for
undeclared variables is left to do later, given that there are
roughly 200 warning.

Change-Id: I99462a1e9232d6e75022912e2df82bc2038476ef
2020-01-25 10:53:26 +00:00
Petr Pchelko
0dc0db7f42 MultiHttpClient: Reset response headers on redirect
We set Curl to follow the redirect with CURLOPT_FOLLOWLOCATION,
however the response headers are being concatenated into a
comma-separated list. Curl follows redirect silently under the hook,
so we end up with a combination of headers from a redirect response
and an after-redirect response. We need to reset the headers.

Change-Id: I9a0f208e5479e5c126d36d788c545a23ff421438
2020-01-16 17:18:30 -08:00
James D. Forrester
0958a0bce4 Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNull
Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
2020-01-10 14:17:13 -08:00
James D. Forrester
4f2d1efdda Coding style: Auto-fix MediaWiki.Classes.UnsortedUseStatements.UnsortedUse
Change-Id: I94a0ae83c65e8ee419bbd1ae1e86ab21ed4d8210
2020-01-10 09:32:25 -08:00
jenkins-bot
94b12c7ba8 Merge "Set visibility on php magic functions __destruct/sleep/wakeup/get/call" 2019-12-09 16:36:13 +00:00
Daimona Eaytoy
598c4d7fcb build: Upgrade phan to 0.9.0
Scalar casts are still allowed (for now), because there's a huge amount
of false positives. Ditto for invalid array offsets.

Thoughts about the rest: luckily, many false positives with array offsets
have gone. Moreover, since *Internal issues are suppressed in the base
config, we can remove inline suppressions.

Unfortunately, there are a couple of new issues about array additions
with only false positives, because apparently they don't take
branches into account.

Change-Id: I5a3913c6e762f77bfdae55051a395fae95d1f841
2019-12-07 20:16:19 +00:00
Umherirrender
eb2373dcd1 Set visibility on php magic functions __destruct/sleep/wakeup/get/call
All the magic functions needs public visibility to be callable from php
internals like garbage collector

Change-Id: I1baf04bf8ff787da880d46e4a6daa77f5a6de73f
2019-12-05 18:52:55 +01:00
Paladox
90a5b971c9 Fix support for HTTP/2 in MultiHttpClient
Under buster, curl uses HTTP/2 (confirmed when running eval):

Buster:
GET xxx HTTP/2

Stretch:
GET xxx HTTP/1.1

The code presumes that it will always be HTTP/1.x.

We fix this by adjusting the regex to match HTTP2.

Bug: T232866
Change-Id: Ibde6036048d5939508df143ec5956abcd0718ad1
2019-12-01 18:20:11 +00:00
Umherirrender
c7ad21c25f Improve param docs
Change-Id: I746a69f6ed01c3ff000da125457df62b02d13b34
2019-11-28 19:08:59 +01:00
Daimona Eaytoy
114ee6e412 Fix new phan errors, part 6
Bug: T231636
Change-Id: I1870b6cbeb31e54fde5e675fec51446b330e06c5
2019-10-20 17:53:48 +00:00
Daimona Eaytoy
95dc119527 Fix new phan errors, part 2
Still mostly doc-only.

Bug: T231636
Change-Id: I65cec6c716ce6859e14da00a12ef71e03603e59a
2019-10-12 10:35:09 +00:00
Aaron Schulz
61a0fd1825 Improve MultiHttpClient connection concurrency/reuse (given PHP >= 7.0.7)
Use CURLMOPT_MAX_HOST_CONNECTIONS to enforce concurrent request limits.
This gives better concurrency than using naïve array_chunk() batches, which
were serialized and treated all URLs as pessimistically from the same host.

Allow connection reuse for multi-URL request batches. This avoids overhead
from reconnections and reduces the number of TIME_WAIT handles when many
batch operations happen in a short time frame. Previously, the use of the
CURLOPT_FORBID_REUSE flag meant that connections were cached but never
reused for multi-URL batches (only single-URL batches).

Connection limits can be verified by running large runMulti() batches
in an interactive shell and inspecting netstat for TCP connections.

Bug: T232128
Change-Id: I851fdc69e0d0d9f9c95dc42781f24d2077a12470
2019-10-08 07:42:32 +00:00
Reedy
134e933e61 Revert "Improve MultiHttpClient connection concurrency and reuse"
This reverts commit 46531d6285.

Bug: T232487
Change-Id: I8b1b829197f0f5758a85cb1547e13448d425aed2
2019-09-10 14:56:38 +00:00
Aaron Schulz
46531d6285 Improve MultiHttpClient connection concurrency and reuse
Use CURLMOPT_MAX_HOST_CONNECTIONS to enforce concurrent request limits.
This gives better concurrency than using naïve array_chunk() batches, which
were serialized and treated all URLs as pessimistically from the same host.

Allow connection reuse for multi-URL request batches. This avoids overhead
from reconnections and reduces the number of TIME_WAIT handles when many
batch operations happen in a short time frame. Previously, the use of the
CURLOPT_FORBID_REUSE flag meant that connections were cached but never
reused for multi-URL batches (only single-URL batches).

Connection limits can be verified by running large runMulti() batches
in an interactive shell and inspecting netstat for TCP connections.

Bug: T232128
Change-Id: I5c5f1eceb3fdb501a8f22f2b949756065f12379a
2019-09-10 11:03:07 +00:00
Daimona Eaytoy
7862475b0d Improve various PHP method doc blocks
Follows-up 5eac6d131c.

Change-Id: I92c9d482fd8693a16b3967e763a4eb40b963c562
2019-09-05 18:45:40 +00:00