Download the PHP package darkghosthunter/laraload without Composer

On this page you can find all versions of the php package darkghosthunter/laraload. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laraload

This package has been superseeded by Laragear/Preload.

Please migrate to the new package.


Laraload

Effortlessly create a PHP Preload Script for your Laravel project.

Requirements

The Opcache extension is not enforced by the package. Just be sure to enable it in your project's PHP main process.

Installation

Call composer and you're done.

What is Preloading? What does this?

Preloading is a new feature for PHP. It "compiles" a list of files into memory, thus making the application code fast without warming up. For that to work, it needs to read a PHP script that "uploads" these files into memory, at process startup.

This allows the first Requests to avoid cold starts, where all the scripts must be loaded by PHP at that moment. Since this step is moved to the process startup, first Requests become faster as all needed scripts are already in memory.

This package wraps the Preloader package that generates a preload file. Once it's generated, you can point the generated list into your php.ini:

After that, the next time PHP starts, this list of files will be preloaded.

Usage

By default, this package constantly recreates your preload script each 500 requests in storage/preload.php. That's it. But you want the details, don't you?

  1. A global terminable middleware checks for non-error response.
  2. Then it calls a custom Condition class.
  3. If the Condition evaluates to true, the Preload Script is generated.
  4. A PreloadCalledEvent is fired with the generation status.

Configuration

Some people may not be happy with the "default" behaviour. Luckily, you can configure your own way to generate the script.

First publish the configuration file:

Let's check the config array:

Enable

By default, Laraload will be automatically enabled on production environments. You can forcefully enable or disable it using an environment variable set to true or false, respectively.

Condition

This package comes with a simple condition class that returns true every 500 requests, which triggers the script generation.

You can define your own condition class to generate the Preload script. This will be called after the request is handled to the browser, and it will be resolved by the Service Container.

The condition is called the same way as a Controller action: as an invokable class or using Class@action notation.

Output

By default, the script is saved in your storage path, but you can change the filename and path to save it as long PHP has permissions to write on it. Double-check your file permissions.

Memory Limit

For most applications, 32MB is fine as a preload limit, but you may fine-tune it for your project specifically.

Method

Opcache allows to preload files using require_once or opcache_compile_file().

Laraload uses opcache_compile_file() for better manageability on the files preloaded. Some unresolved links may output warnings at startup, but nothing critical.

Using require_once will "execute" all files, resolving all the links (imports, parent classes, traits, interfaces, etc.) before compiling it, and may output heavy errors on files that shouldn't be executed. Depending on your application, you may want to use one over the other.

If you plan use require_once, ensure you have set the correct path to the Composer Autoloader, since it will be used to resolve classes, among other files.

Ignore not found files

Version 2.1.0 and onward ignores non-existent files by default. This may work for files created by Laravel at runtime and actively cached by Opcache, but that on deployment are absent, like real-time facades.

You can disable this for any reason, which will throw an Exception if any file is missing, but is recommended leaving it alone unless you know what you're doing.

Include & Exclude directories

For better manageability, you can now append or exclude files from directories using the Symfony Finder, which is included in this package, to retrieve a list of files inside of them with better filtering options.

To do so, add an array of directories, or register a callback receiving a Symfony Finder instance to further filter which files you want to append or exclude. You can do this in your App Service Provider by using the Laravel facade (or injecting Laraload).

FAQ

Yes.

Absolutely. Generating the script is not enough, PHP won't pick up the changes if the script path is empty or the PHP process itself is not restarted completely. You can schedule a server restart with CRON or something.

Check you're using the latest PHP stable version (critical), and Opcache is enabled. Also, check your storage directory is writable.

As a safe-bet, you can use the safe preloader script in darkghosthunter/preloader/helpers/safe-preloader.php and debug the error.

If you're sure this is an error by the package, open an issue with full details and stack trace. If it's a problem on the Preloader itself, issue it there.

Opcache is not enabled when using PHP CLI, and if it is, it will gather wrong statistics. You must let the live application generate the list automatically on demand.

It does not: since the underlying Preloader package may be not heavily requested, it doesn't matter if its excluded or not. The files in Laraload are also not excluded from the list, since these are needed to trigger the Preloader itself without hindering performance.

Laraload creates a preloading script, but doesn't load the script into Opcache. Once the script is generated, you must include it in your php.ini - currently there is no other way to do it. This will take effect only at PHP process startup.

If you still feel your app is slow, remember to benchmark your app, cache your config and views, check your database queries and API calls, and queue expensive logic, among other things. You can also use Laravel Octane on RoadRunner.

Basically: the most hit files in descending order. Each file consumes memory, so the list is soft-cut when the files reach a given memory limit (32MB by default).

Each file is loaded using opcache_compile_file(). If the last file is a class with links outside the list, PHP will issue some warnings, which is normal and intended, but it won't compile the linked files if these were not added before.

You shouldn't. Including all the files of your application may have diminishing returns compared to, for example, only the most requested. You can always benchmark your app yourself to prove this is wrong for your exclusive case.

No, you must use your default condition class or your own class, or use Class@method notation.

Nope. If you are looking for total control, use directly the Preloader package.

Nope. The middleware is not registered if the application is running under Unit Testing environment.

When the Preload script is called, you will receive a PreloadCalledEvent instance with the compilation status (true on success, false on failure). You can add a Listener to dispatch an email or a Slack notification.

If there is a bigger problem, your application logger will catch the exception.

This new version uses Preloader 2, which offers greater flexibility to handle files inside a directory. This approach is incompatible with just issuing directly an array of files, but is more convenient in the long term. Considering that appending and excluding files mostly requires pin-point precision, it was decided to leave it as method calls for this kind of flexibility.

While I encourage you to create your own condition, you can easily change them by adding a container event to your AppServiceProvider.php, under the register() method.

License

This package is licenced by the MIT License.


All versions of laraload with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4.3||^8.0.2
illuminate/support Version ^6.0||^7.0||^8.0
illuminate/http Version ^6.0||^7.0||^8.0
illuminate/events Version ^6.0||^7.0||^8.0
darkghosthunter/preloader Version ^2.2.0
symfony/finder Version ^4.3||^5.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package darkghosthunter/laraload contains the following files

Loading the files please wait ....