Commit Graph

582 Commits

Author SHA1 Message Date
Fabien Potencier
9b81056503 Add a missing replace rule in the main composer.json file 2020-09-16 18:15:11 +02:00
Fabien Potencier
40022972f6 bug #37578 [HttpClient] fix pausing AmpResponse (kelunik)
This PR was merged into the 5.2-dev branch.

Discussion
----------

[HttpClient] fix pausing AmpResponse

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | None
| License       | MIT
| Doc PR        | None

This fixes the pause handler while streaming bodies in `AmpHttpClient`.

Needs to be rebased onto the target branch and needs some test fixes. @nicolas-grekas FYI.

Commits
-------

bf2d1cf6e7 Improve pause handler
2020-08-27 16:48:24 +02:00
Grégoire Pineau
891285475e [Semaphore] Added the component
Few years ago, we have introduced the Lock component. This is a very nice component, but sometime it is not enough. Sometime you need semaphore.

This is why I'm introducing this new component.

From wikipedia:

> In computer science, a semaphore is a variable or abstract data type used to control access to a common resource by multiple processes in a concurrent system such as a multitasking operating system. A semaphore is simply a variable. This variable is used to solve critical section problems and to achieve process synchronization in the multi processing environment. A trivial semaphore is a plain variable that is changed (for example, incremented or decremented, or toggled) depending on programmer-defined conditions.

This new component is more than a variable. This is an abstraction on top of different storage.

To make a quick comparison with a lock:

 * A lock allows only 1 process to access a resource;
 * A semaphore allow N process to access a resource.

Basically, a lock is a semaphore where `N = 1`.

PHP exposes some `sem_*` functions like [`sem_acquire`](http://php.net/sem_acquire). This module provides wrappers for the System V IPC family of functions. It includes semaphores, shared memory and inter-process messaging (IPC).

The Lock component has a storage that works with theses functions. It uses it with `N = 1`.

Wikipedia has some [examples](https://en.wikipedia.org/wiki/Semaphore_(programming)#Examples)

But I can add one more commun use case.

If you are building an async system that process user data, you may want to priorise all jobs. You can achieve that by running at maximum N jobs per user at the same time. If the user has more resources, you give him more concurrent jobs (so a bigger `N`).

Thanks to semaphores, it's pretty easy to know if a new job can be run.

I'm not saying the following services are using semaphore, but they may solve the previous problematic with semaphores. Here is some examples:

 * services like testing platform where a user can test N projects concurrently (travis, circle, appveyor, insight, ...)
 * services that ingest lots of data (newrelic, datadog, blackfire, segment.io, ...))
 * services that send email in batch (campaign monitor, mailchimp, ...)
 * etc...

To do so, since PHP is mono-threaded, you run M PHP workers. And in each worker, you look for for the next job. When you grab a job, you try to acquires a semaphore. If you got it, you process the job. If not you try another job.

FTR in other language, like Go, there are no need to run M workers, one is enough.

```php
<?php

use Symfony\Component\Lock\LockFactory;
use Symfony\Component\Lock\Store\RedisStore as LockRedisStore;
use Symfony\Component\Semaphore\SemaphoreFactory;
use Symfony\Component\Semaphore\Store\RedisStore;

require __DIR__.'/vendor/autoload.php';

$redis = new Redis();
$redis->connect('172.17.0.2');

// Internally, Semaphore needs a lock
$lock = (new LockFactory(new LockRedisStore($redis)))->createLock('test:lock', 1);

// Create a semaphore:
// * name = test
// * limit = 3 (it means only 3 process are allowed)
// * ttl = 10 seconds : Maximum expected semaphore duration in seconds
$semaphore = (new SemaphoreFactory($lock, new RedisStore($redis)))->createSemaphore('test', 3, 10);

if (!$semaphore->acquire()) {
    echo "Could not acquire the semaphore\n";
    exit(1);
}

// The semaphore has been acquired

// Do the heavy job
for ($i = 0; $i < 100; ++$i) {
    sleep(1);
    // Before the expiration, refresh the semaphore if the job is not finished yet
    if ($i % 9 === 0) {
        $semaphore->refresh();
    }
}

// Release it when finished
$semaphore->release();
```

I looked at [packagist](https://packagist.org/?query=semaphore) and:

 * most of packages are using a semaphore storage for creating a lock. So there are not relevant here;
 * some packages need an async framework to be used (amphp for example);
 * the only packages really implementing a semaphore, has a really low code quality and some bugs.

1. I initially copied the Lock component since the external API is quite similar;
1. I simplified it a lot for the current use case;
1. I implemented the RedisStorage according the [redis book](https://redislabs.com/ebook/part-2-core-concepts/chapter-6-application-components-in-redis/6-3-counting-semaphores/;)
1. I forced a TTL on the storage.
2020-08-27 14:35:29 +02:00
Niklas Keller
bf2d1cf6e7 Improve pause handler 2020-08-26 12:30:57 +02:00
Fabien Potencier
374a0b2eb5 Merge branch '5.1'
* 5.1:
  fix passing arguments to call_user_func_array() on PHP 8
  allow Doctrine DBAL 3
  [Filesystem] fix test on PHP 8
2020-08-21 19:20:41 +02:00
Fabien Potencier
0611b6331c Merge branch '4.4' into 5.1
* 4.4:
  fix passing arguments to call_user_func_array() on PHP 8
  allow Doctrine DBAL 3
  [Filesystem] fix test on PHP 8
2020-08-21 19:19:47 +02:00
Christian Flothmann
967331e63a allow Doctrine DBAL 3 2020-08-21 14:55:23 +02:00
Antonio Pauletich
8e6d0df3ec
Add Beanstalkd Messenger bridge 2020-08-13 09:43:16 +02:00
Fabien Potencier
b912af9261 Merge branch '5.1'
* 5.1:
  Fix typo
  Fix deprecated libxml_disable_entity_loader
  Add Tagalog translations for validator messages 94, 95, 96 and 99
  PHPUnit's assertContains() performs strict comparisons now.
  [ClassLoader][Routing] Fix namespace parsing on php 8.
  Fix deprecated libxml_disable_entity_loader
  Made reference to PHPUnit\Util\XML::loadfile php5-compatible.
  [Validator] Add missing translations for german and vietnamese
  Modernized deprecated PHPUnit assertion calls
  [Console] The message of "class not found" errors has changed in php 8.
  The PHPUnit\Util\XML class has been removed in PHPUnit 9.3.
  [Console] Make sure we pass a numeric array of arguments to call_user_func_array().
  Remove outdated references from base_js.html.twig file
  [String] We cannot have a "provides" function in test cases.
  Typo: somes styles fixed
  [Serializer] Fix that it will never reach DOMNode
  [Validator] sync translations
  [VarDumper] Improve previous fix on light array coloration
  [Cache] Fix #37667
2020-08-10 10:10:48 +02:00
Fabien Potencier
c44c606b11 Merge branch '4.4' into 5.1
* 4.4:
  Fix typo
  Fix deprecated libxml_disable_entity_loader
  Add Tagalog translations for validator messages 94, 95, 96 and 99
  PHPUnit's assertContains() performs strict comparisons now.
  [ClassLoader][Routing] Fix namespace parsing on php 8.
  Fix deprecated libxml_disable_entity_loader
  Made reference to PHPUnit\Util\XML::loadfile php5-compatible.
  [Validator] Add missing translations for german and vietnamese
  Modernized deprecated PHPUnit assertion calls
  [Console] The message of "class not found" errors has changed in php 8.
  The PHPUnit\Util\XML class has been removed in PHPUnit 9.3.
  [Console] Make sure we pass a numeric array of arguments to call_user_func_array().
  [Serializer] Fix that it will never reach DOMNode
  [Validator] sync translations
  [VarDumper] Improve previous fix on light array coloration
  [Cache] Fix #37667
2020-08-10 10:03:57 +02:00
Fabien Potencier
3a04739a83 Merge branch '3.4' into 4.4
* 3.4:
  Add Tagalog translations for validator messages 94, 95, 96 and 99
  PHPUnit's assertContains() performs strict comparisons now.
  [ClassLoader][Routing] Fix namespace parsing on php 8.
  Fix deprecated libxml_disable_entity_loader
  Made reference to PHPUnit\Util\XML::loadfile php5-compatible.
  [Validator] Add missing translations for german and vietnamese
  Modernized deprecated PHPUnit assertion calls
  [Console] The message of "class not found" errors has changed in php 8.
  The PHPUnit\Util\XML class has been removed in PHPUnit 9.3.
  [Console] Make sure we pass a numeric array of arguments to call_user_func_array().
  [Serializer] Fix that it will never reach DOMNode
  [Validator] sync translations
  [VarDumper] Improve previous fix on light array coloration
  [Cache] Fix #37667
2020-08-10 09:27:51 +02:00
Alexander M. Turek
ab417f7040 Modernized deprecated PHPUnit assertion calls 2020-08-09 10:13:48 +02:00
Nicolas Grekas
91487707db Merge branch '5.1'
* 5.1:
  Allow doctrine/persistence 2
  Fix Redis tests
  [DoctrineBridge] Bump doctrine/data-fixtures.
2020-07-23 18:56:54 +02:00
Nicolas Grekas
20cf5df00b Merge branch '5.0' into 5.1
* 5.0:
  Allow doctrine/persistence 2
  Fix Redis tests
  [DoctrineBridge] Bump doctrine/data-fixtures.
2020-07-23 18:55:47 +02:00
Nicolas Grekas
081ad138f7 Merge branch '4.4' into 5.0
* 4.4:
  Allow doctrine/persistence 2
  Fix Redis tests
  [DoctrineBridge] Bump doctrine/data-fixtures.
2020-07-23 18:54:02 +02:00
Alexander M. Turek
cd22fe6c92 Allow doctrine/persistence 2 2020-07-23 18:49:41 +02:00
Nicolas Grekas
4a8f11c1dd Merge branch '3.4' into 4.4
* 3.4:
  Fix Redis tests
  [DoctrineBridge] Bump doctrine/data-fixtures.
2020-07-23 18:48:29 +02:00
Alexander M. Turek
4b611015d5 [DoctrineBridge] Bump doctrine/data-fixtures. 2020-07-23 14:17:19 +02:00
Nicolas Grekas
092632dc14 Merge branch '5.1'
* 5.1: (28 commits)
  [DI] fix
  Use "composer/package-versions-deprecated" when possible
  Fix
  Small update in our internal terminology
  Fix support for PHP8 union types
  [VarDumper] fix typo
  [Lock][Messenger] Fix precedence of DSN options for 5.1
  Fix support for PHP8 union types
  [FrameworkBundle] preserve dots in query-string when redirecting
  [3.4] Fix support for PHP8 union types
  [PhpUnitBridge] Streamline ansi/no-ansi of composer according to phpunit --colors option
  [3.4] Small update in our internal terminology
  [Cache] fix compat with DBAL v3
  Remove unnecessary null check
  [HttpFoundation] Allow `null` in InputBag@set
  [HttpClient] Convert CurlHttpClient::handlePush() to instance method
  Fix package rename when releasing
  bumped Symfony version to 5.1.3
  updated VERSION for 5.1.2
  updated CHANGELOG for 5.1.2
  ...
2020-06-18 21:55:03 +02:00
Nicolas Grekas
eea6abf318 Merge branch '5.0' into 5.1
* 5.0:
  [DI] fix
  Use "composer/package-versions-deprecated" when possible
  Fix
2020-06-18 21:54:27 +02:00
Nicolas Grekas
f3d9cfe8db Merge branch '4.4' into 5.0
* 4.4:
  [DI] fix
  Use "composer/package-versions-deprecated" when possible
  Fix
2020-06-18 21:53:24 +02:00
Nicolas Grekas
03b9ff177d Use "composer/package-versions-deprecated" when possible 2020-06-18 21:48:48 +02:00
Nicolas Grekas
dadc606800 Merge branch '5.1'
* 5.1:
  [Console] Reset question validator attempts only for actual stdin (bis)
  Fix CookieClearingLogoutListener DI configuration
  [HttpFoundation] use InputBag for Request::$request only if data is coming from a form
  Make PhpDocExtractor compatible with phpDocumentor v5
  fixed prototype block prefixes hierarchy of the CollectionType
  Reset question validator attempts only for actual stdin
  fixed block prefixes hierarchy of the CollectionType
  bumped Symfony version to 5.0.11
  updated VERSION for 5.0.10
  updated CHANGELOG for 5.0.10
  bumped Symfony version to 4.4.11
  updated VERSION for 4.4.10
  updated CHANGELOG for 4.4.10
2020-06-15 14:59:35 +02:00
Fabien Potencier
5562d5c1ba Merge branch '5.0' into 5.1
* 5.0:
  Make PhpDocExtractor compatible with phpDocumentor v5
  Reset question validator attempts only for actual stdin
  bumped Symfony version to 5.0.11
  updated VERSION for 5.0.10
  updated CHANGELOG for 5.0.10
  bumped Symfony version to 4.4.11
  updated VERSION for 4.4.10
  updated CHANGELOG for 4.4.10
2020-06-15 13:50:15 +02:00
Fabien Potencier
6fff7b3672 Merge branch '4.4' into 5.0
* 4.4:
  Make PhpDocExtractor compatible with phpDocumentor v5
  Reset question validator attempts only for actual stdin
  bumped Symfony version to 4.4.11
  updated VERSION for 4.4.10
  updated CHANGELOG for 4.4.10
2020-06-15 13:49:47 +02:00
DerManoMann
b1f8e5a80a Make PhpDocExtractor compatible with phpDocumentor v5
Version 5 of phpDocumentor introduced some changes to the
`getTagsByName()` method that break the `PhpDocExtractor`.
More specific, it now returns an instance of `InvalidTag` instead of
`null` when parsing an invalid tag.
2020-06-15 09:00:35 +12:00
Nicolas Grekas
08afeed555 Merge branch '4.4' into 5.0
* 4.4: (27 commits)
  [Serializer] minor cleanup
  fix merge
  Run PHP 8 as 7.4.99
  Remove calls to deprecated ReflectionParameter::getClass().
  [VarDumper] fix PHP 8 support
  Add php 8 to travis.
  [Cache] Accessing undefined constants raises an Error in php8
  [Cache] allow DBAL v3
  Skip Doctrine DBAL on php 8 until we have a compatible version.
  [DomCrawler] Catch expected ValueError.
  Made method signatures compatible with their corresponding traits.
  [ErrorHandler] Apply php8 fixes from Debug component.
  [DomCrawler] Catch expected ValueError.
  [Validator] Catch expected ValueError.
  [VarDumper] ReflectionFunction::isDisabled() is deprecated.
  [BrowserKit] Raw body with custom Content-Type header
  [PropertyAccess] Parse php 8 TypeErrors correctly.
  [Intl] Fix call to ReflectionProperty::getValue() for static properties.
  [HttpKernel] Prevent calling method_exists() with non-string values.
  Fix wrong roles comparison
  ...
2020-05-23 14:58:59 +02:00
Nicolas Grekas
ae49c3c649 fix merge 2020-05-23 14:37:04 +02:00
Fabien Potencier
4fe2b4d1d5 Bump min Doctrine DBAL requirement to 2.10 2020-05-22 19:21:20 +02:00
Nicolas Grekas
430b884570 Merge branch '5.1'
* 5.1:
  [PhpUnitBridge] fix leftover
  [PhpUnitBridge] fix installing under PHP >= 8
  Use ">=" for the "php" requirement
  bump icu 67.1
  [DI] Remove preload primitive types
  [Validator] Add missing translations of nn locale
  [HttpKernel] Fix that the `Store` would not save responses with the X-Content-Digest header present
  [Intl] bump icu 67.1
  [Validator] allow passing a validator to Validation::createCallable()
2020-05-20 19:44:07 +02:00
Nicolas Grekas
e65cdb685f Merge branch '5.0' into 5.1
* 5.0:
  [PhpUnitBridge] fix leftover
  [PhpUnitBridge] fix installing under PHP >= 8
  Use ">=" for the "php" requirement
  bump icu 67.1
2020-05-20 19:43:50 +02:00
Nicolas Grekas
b429b15eb5 Merge branch '4.4' into 5.0
* 4.4:
  [PhpUnitBridge] fix leftover
  [PhpUnitBridge] fix installing under PHP >= 8
  Use ">=" for the "php" requirement
  bump icu 67.1
2020-05-20 19:38:26 +02:00
Nicolas Grekas
f8aa0873cf Use ">=" for the "php" requirement 2020-05-20 10:37:50 +02:00
Fabien Potencier
25c4889c8e updated version to 5.2 2020-05-16 14:09:30 +02:00
Nicolas Grekas
f8616f8eae Merge branch '5.0'
* 5.0:
  [PhpUnitBridge] fix bad test
  [4.4] CS fixes
  [3.4] CS fixes
  Disable phpunit verbosity
  Queue name is a required parameter
  [FrameworkBundle] display actual target for error in AssetsInstallCommand
  Remove patches for Doctrine bugs and deprecations
  [Mime] fix bad method call on "EmailAddressContains"
  [DI][EventDispatcher] added contract for implementation
2020-05-08 14:36:29 +02:00
Nicolas Grekas
0b34b39cc8 Merge branch '4.4' into 5.0
* 4.4:
  [PhpUnitBridge] fix bad test
  [4.4] CS fixes
  [3.4] CS fixes
  Disable phpunit verbosity
  Queue name is a required parameter
  [FrameworkBundle] display actual target for error in AssetsInstallCommand
  Remove patches for Doctrine bugs and deprecations
  [Mime] fix bad method call on "EmailAddressContains"
  [DI][EventDispatcher] added contract for implementation
2020-05-08 14:34:39 +02:00
Nicolas Grekas
2dbfeb9db9 Merge branch '3.4' into 4.4
* 3.4:
  [FrameworkBundle] display actual target for error in AssetsInstallCommand
  Remove patches for Doctrine bugs and deprecations
  [DI][EventDispatcher] added contract for implementation
2020-05-08 11:58:40 +02:00
Grégoire Paris
2f305cdc83 Remove patches for Doctrine bugs and deprecations 2020-05-08 11:45:13 +02:00
Nicolas Grekas
02d9597a41 Merge branch '5.0'
* 5.0:
  Force doctrine/dbal <=2.10.2 when testing
2020-05-05 15:53:42 +02:00
Nicolas Grekas
cd21c8208e Merge branch '4.4' into 5.0
* 4.4:
  Force doctrine/dbal <=2.10.2 when testing
2020-05-05 15:53:15 +02:00
Nicolas Grekas
f8bedf4e79 Merge branch '3.4' into 4.4
* 3.4:
  Force doctrine/dbal <=2.10.2 when testing
2020-05-05 15:52:57 +02:00
Nicolas Grekas
d1953d61cd Force doctrine/dbal <=2.10.2 when testing 2020-05-05 15:43:18 +02:00
Jérémy Derussé
7c4888eed1 [AmazonSqsMessenger] Use AsyncAws to handle SQS communication 2020-05-03 18:22:01 +02:00
Jérémy Derussé
21243874bc [Mailer] Use AsyncAws to handle SES requests 2020-05-03 16:23:41 +02:00
Nicolas Grekas
6dc7d8b211 Merge branch '5.0'
* 5.0:
  [PhpUnitBridge] add PolyfillTestCaseTrait::expectExceptionMessageMatches to provide FC with recent phpunit versions
  [Messenger] Make sure redis transports are initialized correctly
  Remove return type for Twig function workflow_metadata()
  [DI] fix typo
2020-04-15 18:09:08 +02:00
Nicolas Grekas
4f8f3747d3 Merge branch '4.4' into 5.0
* 4.4:
  [PhpUnitBridge] add PolyfillTestCaseTrait::expectExceptionMessageMatches to provide FC with recent phpunit versions
  [Messenger] Make sure redis transports are initialized correctly
  Remove return type for Twig function workflow_metadata()
  [DI] fix typo
2020-04-15 17:59:10 +02:00
soyuka
cfd5a29eaf [PhpUnitBridge] add PolyfillTestCaseTrait::expectExceptionMessageMatches to provide FC with recent phpunit versions 2020-04-15 17:55:41 +02:00
Nicolas Grekas
53b0f63bc3 [String] leverage Stringable from PHP 8 2020-03-13 11:54:27 +01:00
Grégoire Pineau
c3f14dd0f4 [UID] Added the component + Added support for UUID 2020-03-12 18:21:37 +01:00
Nicolas Grekas
ef113feeb3 [HttpClient] Add portable HTTP/2 implementation based on Amp's HTTP client 2020-03-02 14:21:45 +01:00