-
Notifications
You must be signed in to change notification settings - Fork 11.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Laracon 2024 #52710
Merged
Merged
Laracon 2024 #52710
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
ed4884a
work on defer
taylorotwell 50aae67
refine defer
taylorotwell efa71ff
refactor
taylorotwell 714cef2
formatting
taylorotwell 98b4d4c
fix new
taylorotwell cfd40dd
fix status code
taylorotwell f39acdc
handle job releases after exceptions
taylorotwell b4b7a75
add job attempted event
taylorotwell cff79e4
formatting
taylorotwell 3ec696c
formatting
taylorotwell b7fa85f
first pass at swr
taylorotwell c9e1b7d
rename method
taylorotwell 11977e7
add swr test
taylorotwell 569c6f5
starting concurrency
taylorotwell 5ec9d6b
wip
taylorotwell dc3d5d7
formatting
taylorotwell 8ce4659
driver based
taylorotwell c89d85a
formatting
taylorotwell ecd8949
block on web
taylorotwell 5e68fb3
fix docblock
taylorotwell 65556fa
first pass at local temporary files
taylorotwell f467116
remove imports
taylorotwell 69b658b
docblock
taylorotwell d2db712
work on routing
taylorotwell 989a5f5
allow customization of serve behavior
taylorotwell 1058023
work on local file serving
taylorotwell 3de3331
route caching
taylorotwell b6656e3
move route caching check
taylorotwell 9913bbc
extract file
taylorotwell 318218c
formatting
taylorotwell 14a9ae2
formatting
taylorotwell 984c4a2
formatting
taylorotwell 8ac5618
add test
taylorotwell 308f142
formatting
taylorotwell 1dd890a
add cache control
taylorotwell cc64665
use defer in concurrency
taylorotwell 14dc1ad
allow return from sleep
taylorotwell 03d198b
adjust sleep behavior
taylorotwell 7726a92
add config file
taylorotwell 1a8853e
testing
taylorotwell d9da8ae
add while to sleep
taylorotwell eb207ac
add autoload
taylorotwell 3229285
add function
taylorotwell 9ed9953
Apply fixes from StyleCI
StyleCIBot d71f4ee
Concurrency Improvements (#52713)
crynobone 419893c
adjust php binary
taylorotwell 516cd78
Merge branch 'laracon-2024' of github.com:laravel/framework into lara…
taylorotwell 16b85a3
php executable finder
taylorotwell 1de6373
false arg
taylorotwell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
return [ | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Default Concurrency Driver | ||
|-------------------------------------------------------------------------- | ||
| | ||
| This option determines the default concurrency driver that will be used | ||
| by Laravel's concurrency functions. By default, concurrent work will | ||
| be sent to isolated PHP processes which will return their results. | ||
| | ||
| Supported: "process", "fork", "sync" | ||
| | ||
*/ | ||
|
||
'driver' => env('CONCURRENCY_DRIVER', 'process'), | ||
|
||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/.github export-ignore | ||
.gitattributes export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
namespace Illuminate\Concurrency; | ||
|
||
use Illuminate\Process\Factory as ProcessFactory; | ||
use Illuminate\Support\MultipleInstanceManager; | ||
use RuntimeException; | ||
use Spatie\Fork\Fork; | ||
|
||
/** | ||
* @mixin \Illuminate\Contracts\Concurrency\Driver | ||
*/ | ||
class ConcurrencyManager extends MultipleInstanceManager | ||
{ | ||
/** | ||
* Get a driver instance by name. | ||
* | ||
* @param string|null $name | ||
* @return mixed | ||
*/ | ||
public function driver($name = null) | ||
{ | ||
return $this->instance($name); | ||
} | ||
|
||
/** | ||
* Create an instance of the process concurrency driver. | ||
* | ||
* @param array $config | ||
* @return \Illuminate\Concurrency\ProcessDriver | ||
*/ | ||
public function createProcessDriver(array $config) | ||
{ | ||
return new ProcessDriver($this->app->make(ProcessFactory::class)); | ||
} | ||
|
||
/** | ||
* Create an instance of the fork concurrency driver. | ||
* | ||
* @param array $config | ||
* @return \Illuminate\Concurrency\ForkDriver | ||
*/ | ||
public function createForkDriver(array $config) | ||
{ | ||
if (! $this->app->runningInConsole()) { | ||
throw new RuntimeException('Due to PHP limitations, the fork driver may not be used within web requests.'); | ||
} | ||
|
||
if (! class_exists(Fork::class)) { | ||
throw new RuntimeException('Please install the "spatie/fork" Composer package in order to utilize the "fork" driver.'); | ||
} | ||
|
||
return new ForkDriver; | ||
} | ||
|
||
/** | ||
* Create an instance of the sync concurrency driver. | ||
* | ||
* @param array $config | ||
* @return \Illuminate\Concurrency\SyncDriver | ||
*/ | ||
public function createSyncDriver(array $config) | ||
{ | ||
return new SyncDriver; | ||
} | ||
|
||
/** | ||
* Get the default instance name. | ||
* | ||
* @return string | ||
*/ | ||
public function getDefaultInstance() | ||
{ | ||
return $this->app['config']['concurrency.default'] ?? 'process'; | ||
} | ||
|
||
/** | ||
* Set the default instance name. | ||
* | ||
* @param string $name | ||
* @return void | ||
*/ | ||
public function setDefaultInstance($name) | ||
{ | ||
$this->app['config']['concurrency.default'] = $name; | ||
} | ||
|
||
/** | ||
* Get the instance specific configuration. | ||
* | ||
* @param string $name | ||
* @return array | ||
*/ | ||
public function getInstanceConfig($name) | ||
{ | ||
return $this->app['config']->get( | ||
'concurrency.drivers.'.$name, ['driver' => $name], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Illuminate\Concurrency; | ||
|
||
use Illuminate\Contracts\Support\DeferrableProvider; | ||
use Illuminate\Support\ServiceProvider; | ||
|
||
class ConcurrencyServiceProvider extends ServiceProvider implements DeferrableProvider | ||
{ | ||
/** | ||
* Register the service provider. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
$this->app->singleton(ConcurrencyManager::class, function ($app) { | ||
return new ConcurrencyManager($app); | ||
}); | ||
} | ||
|
||
/** | ||
* Get the services provided by the provider. | ||
* | ||
* @return array | ||
*/ | ||
public function provides() | ||
{ | ||
return [ | ||
ConcurrencyManager::class, | ||
]; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/Illuminate/Concurrency/Console/InvokeSerializedClosureCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace Illuminate\Concurrency\Console; | ||
|
||
use Illuminate\Console\Command; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Throwable; | ||
|
||
#[AsCommand(name: 'invoke-serialized-closure')] | ||
class InvokeSerializedClosureCommand extends Command | ||
{ | ||
/** | ||
* The console command signature. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'invoke-serialized-closure {code? : The serialized closure}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Invoke the given serialized closure'; | ||
|
||
/** | ||
* Indicates whether the command should be shown in the Artisan command list. | ||
* | ||
* @var bool | ||
*/ | ||
protected $hidden = true; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return void | ||
* | ||
* @throws \RuntimeException | ||
*/ | ||
public function handle() | ||
{ | ||
try { | ||
$this->output->write(json_encode([ | ||
'successful' => true, | ||
'result' => serialize($this->laravel->call(match (true) { | ||
! is_null($this->argument('code')) => unserialize($this->argument('code')), | ||
isset($_SERVER['LARAVEL_INVOKABLE_CLOSURE']) => unserialize($_SERVER['LARAVEL_INVOKABLE_CLOSURE']), | ||
default => fn () => null, | ||
})), | ||
])); | ||
} catch (Throwable $e) { | ||
report($e); | ||
|
||
$this->output->write(json_encode([ | ||
'successful' => false, | ||
'exception' => get_class($e), | ||
'message' => $e->getMessage(), | ||
'file' => $e->getFile(), | ||
'line' => $e->getLine(), | ||
])); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Illuminate\Concurrency; | ||
|
||
use Closure; | ||
use Illuminate\Foundation\Defer\DeferredCallback; | ||
use Illuminate\Support\Arr; | ||
use Spatie\Fork\Fork; | ||
|
||
class ForkDriver | ||
{ | ||
/** | ||
* Run the given tasks concurrently and return an array containing the results. | ||
*/ | ||
public function run(Closure|array $tasks): array | ||
{ | ||
/** @phpstan-ignore class.notFound */ | ||
return Fork::new()->run(...Arr::wrap($tasks)); | ||
} | ||
|
||
/** | ||
* Start the given tasks in the background after the current task has finished. | ||
*/ | ||
public function defer(Closure|array $tasks): DeferredCallback | ||
{ | ||
return defer(fn () => $this->run($tasks)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) Taylor Otwell | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious what you think about calling this (or aliasing it to)
Cache::throttle()
orCache::debounce()
, since it is literally throttling/debouncing the refreshing of the cached value. Regardless can't wait to use it!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another is why a 2-element array for ttl and not spreading it as, say,
($key, $ttlFresh, $ttlStale, ...)