-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- deferred functions - concurrency - local private files - cache::flexible - log() function
- Loading branch information
1 parent
2f83567
commit c44aa73
Showing
38 changed files
with
1,500 additions
and
17 deletions.
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.