Download the PHP package winter/wn-octane-plugin without Composer

On this page you can find all versions of the php package winter/wn-octane-plugin. 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 wn-octane-plugin

Octane Plugin

Tests MIT License

This plugin lets you run Winter CMS on Laravel Octane, so FrankenPHP, Swoole or RoadRunner serves your site instead of PHP-FPM.

Under Octane, your app boots once and the same process handles request after request. Winter was written for PHP-FPM, where the process goes away after every request, so it never had to clean up after itself. In a worker, the logged-in user, permission-filtered menus, settings, view data and even an open database transaction would all still be there when the next request came in, possibly from someone else. Most of what this plugin does is clear that state.

What the plugin does:

Requirements

Installation

Install the plugin with Composer:

Next, run the migrations and install Octane. If you use a public folder, republish your public directory too.

Then start a worker:

For server configuration, deployment and tuning, see the Octane documentation.

FrankenPHP

Start the server with php artisan octane:frankenphp. The plugin swaps Octane's command for one that understands Winter's layout, which changes three things.

The Caddyfile. Winter serves from the project root, so Octane's own Caddyfile would hand out composer.json, .env and your logs, and would run any PHP file in the project. The plugin's caddy/Caddyfile serves only what Winter's .htaccess whitelists (storage/app/uploads/public, storage/app/media, storage/app/resized, storage/temp/public, .well-known, and the assets and resources folders of themes, plugins and modules) and sends everything else to the worker. You get this file unless you pass --caddyfile. If you bring your own, apply the same whitelist.

The Caddyfile sends Cache-Control: max-age=604800, public, must-revalidate with those files, so browsers and CDNs keep them for a week. To set FrankenPHP's global options, such as max_idle_time or max_wait_time, put them in the WINTER_OCTANE_FRANKENPHP_OPTIONS environment variable or in octane.caddy.env, one option per line. The Caddyfile inserts them in its frankenphp block.

Restricted back-end pages. On the back-end's sign-in (backend/auth), update (system/updates) and install (system/install) pages, Winter under PHP-FPM registers only its elevated plugins, so you can still sign in and disable a plugin that broke the back end. A worker boots once with every plugin loaded, so the Caddyfile sends those paths, under your cms.backendUri, to Winter's index.php on a regular PHP thread, which boots for each request the way PHP-FPM does.

Those pages pay for a full boot every time and share FrankenPHP's regular threads, so raise its num_threads option if you get bursts of sign-ins or run long updates. Core's other restricted path, /combine/, stays on the worker, which already has every plugin booted. If you bring your own Caddyfile, add the @restricted rewrite before the worker rewrite. The command sets the WINTER_OCTANE_RESTRICTED_PATHS value it reads.

The worker file. If frankenphp-worker.php is missing, or is the untouched copy that octane:install writes, the plugin installs its own. Octane's version looks for your app one directory above the web root, and it loads Composer's autoloader without Winter's bootstrap/autoload.php, which lets Laravel's global helpers such as trans() replace Winter's. The plugin leaves any other frankenphp-worker.php alone. If yours came from an earlier version of this README, delete it so the plugin can install the current one.

Swoole and RoadRunner

Winter serves from the project root, so Octane's Swoole and RoadRunner commands would serve any file in your project, including .env, composer.json, your logs and your SQLite database. RoadRunner would also serve the source of every PHP file. Neither server can limit static files to a list of paths, so the plugin's octane:swoole and octane:roadrunner commands turn static file serving off:

The worker then serves the same whitelisted paths as the Caddyfile and passes everything else to Winter. Every file served this way goes through Octane and Winter's global middleware, so on a busy site, put a web server or CDN in front to serve those paths.

These two servers can't send a request anywhere but the worker, so non-elevated plugins stay loaded on the back-end's sign-in, update and install pages, unlike under PHP-FPM or FrankenPHP. If a non-elevated plugin breaks the back end, it breaks the sign-in page too.

Performance

A long-running worker can hold on to work that PHP-FPM has to repeat, so the plugin does that for you. Apart from warm-up requests, there's nothing to configure, and none of it runs under PHP-FPM.

Theme templates. If a theme reads from a plain FileDatasource, the worker reads it through WorkerFileDatasource instead. That class remembers resolved paths and file contents, but still stats the file on every read, so you'll see a template change on the next read. It leaves subclasses of FileDatasource alone, along with the AutoDatasource that core builds for child themes and database templates.

The worker also keeps the templates Halcyon parsed from those themes in memory, instead of reading them from the cache store on every request. Halcyon still compares each one's modification time with the file's before using it, as it does with the cache store's copy, so an edit on disk or in the back-end editor reaches the next request in every worker. Emptying the cache store, for example with php artisan cache:clear, drops them from every worker's memory too. To drop them without emptying the store, forget the winter.octane.template-generation cache key.

Symlinks inside a theme get checked on every read. If you repoint a symlink on the theme directory or a directory above it while a worker is running, reload the worker.

Parsed YAML. With app.debug off, values cached by Yaml::parseFile() stay in the worker's memory between requests. The file's modification time is part of the cache key, so an edit that changes it gets parsed again.

The class scan. The request-state reset has to find the classes that use certain traits. The first full scan now happens when the worker starts, so your first request doesn't pay for it.

Warm-up requests. A worker's first request is slower than the rest, because it loads classes and builds whatever your site keeps for the life of the worker. A server that prefers one worker leaves the others unused until traffic rises, so they pay for that when the site is busiest. To have each worker pay when it starts instead, list the paths to request in config/octane.php:

Each worker requests those paths on your app.url before it serves a visitor, and throws the responses away. A warm-up request is a GET from a visitor with no cookies, and it goes through your middleware like any other, so it can start a session or count as a page view. Pick a public page that does the work your real pages do. To leave something out of a warm-up request, check for the request attribute: request()->attributes->get(\Winter\Octane\Classes\WarmsWorker::WARM_UP_ATTRIBUTE). A warm-up request that fails, or that gets a 4xx or 5xx response, is logged and the worker starts anyway. A worker takes no traffic until its warm-up requests finish, so keep the list short.

Warm-up requests are sent under FrankenPHP and Swoole. A RoadRunner worker starts when its first request has already arrived, so a warm-up request there would only make that visitor wait, and the plugin sends none. Swoole's task workers send none either, because they serve no requests.

Disabling the plugin

Don't disable this plugin while Octane is serving your site. A disabled plugin never loads, so the reset stops running while the workers keep serving requests, and users end up sharing request state, including who's logged in. To stop using Octane, switch back to PHP-FPM first. Once no worker is running, the plugin does nothing and you can safely disable or remove it.

The plugin is registered as elevated so that it still loads on the protected routes and console commands where Winter skips normal plugin initialization.

For plugin developers

If your plugin caches request data on the plugin class, a singleton or a static property, define resetWorkerState() to clear it. It runs at the start of every Octane operation:

A few things to watch for:

If your plugin requires this one, you can add implements \Winter\Octane\Contracts\ResetsWorkerState for the compile-time check. PHP won't load a class that implements a missing interface, so if your plugin also runs without this one installed, define the method and skip the interface.

Keeping cache values between requests

The reset also empties the in-memory layer of Winter's cache stores, so apart from parsed YAML and theme templates, anything your request read from the cache gets read from the store again next time. To keep values that every request needs, such as site-wide settings, define keepWorkerCacheValue(). It runs at the start of every Octane operation for each key in memory, and a value stays when it returns true:

A few things to watch for:

Finding leaks with PHPStan

The plugin ships PHPStan rules that find static state a worker would carry from one request to the next. Add the extension to your project's phpstan.neon:

It reports two things:

A static property counts as cleared when a plugin's resetWorkerState() (or a method it calls directly) writes it, when code further down that call chain assigns it a constant such as [] or null or unsets it, when a terminating() callback or a RequestReceived listener clears it, or when this plugin's own reset lists include it. A reset in test code, or in a closure that reset code only defines, does not count. The rules skip test code, writes made while the worker boots (a plugin's register() and boot(), and functions only those call), a property the same function puts back in a finally block, WeakMap properties, and values computed only from constants, reflection and pure built-in functions.

To fix a finding, clear the property in your plugin's resetWorkerState(). When keeping the value is safe, for example because every request would compute the same value, mark the property and say why:

The rule matches any attribute named WorkerScoped, so a plugin that also runs without this one can declare its own, as long as PHPStan can find that class. For a static $var, put a /** @octane-worker-scoped <reason> */ docblock above the statement.

PHPStan's result cache does not notice changes to the rules' helper classes. Run vendor/bin/phpstan clear-result-cache after updating this plugin.

Tests

The test suite boots one application and sends requests through Octane's ApplicationGateway, the same path a worker uses. Run it from the plugin directory inside a Winter installation:

License

This plugin is licensed under the MIT license.


All versions of wn-octane-plugin with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
composer/installers Version ~1.0 || ~2.0
laravel/octane Version ^2.5
winter/storm Version ^1.3
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 winter/wn-octane-plugin contains the following files

Loading the files please wait ...