Skip to content

Commit c38d7de

Browse files
authored
Merge pull request #8597 from ddevsr/preload
docs: preload notes
2 parents 8125c13 + 4d121a7 commit c38d7de

File tree

4 files changed

+51
-4
lines changed

4 files changed

+51
-4
lines changed

preload.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ class preload
4949
*/
5050
private array $paths = [
5151
[
52-
'include' => __DIR__ . '/vendor/codeigniter4/framework/system',
52+
'include' => __DIR__ . '/vendor/codeigniter4/framework/system', // Change this path if using manual installation
5353
'exclude' => [
5454
// Not needed if you don't use them.
5555
'/system/Database/OCI8/',
5656
'/system/Database/Postgre/',
57+
'/system/Database/SQLite3/',
5758
'/system/Database/SQLSRV/',
5859
// Not needed.
5960
'/system/Database/Seeder.php',

user_guide_src/source/general/managing_apps.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ they can find the **Paths** configuration file:
5050

5151
.. literalinclude:: managing_apps/003.php
5252

53+
.. _running-multiple-app:
54+
5355
Running Multiple Applications with one CodeIgniter Installation
5456
===============================================================
5557

user_guide_src/source/installation/deployment.rst

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,33 @@ See :ref:`file-locator-caching`.
5959
PHP Preloading
6060
==============
6161

62-
If you want to use `Preloading <https://www.php.net/manual/en/opcache.preloading.php>`_,
63-
we provide a
64-
`preload script <https://github.com/codeigniter4/CodeIgniter4/blob/develop/preload.php>`_.
62+
With PHP preloading, you can instruct the server to load essential files like functions and classes into memory during startup.
63+
This means these elements are readily available for all requests, skipping the usual loading process and boosting your
64+
application's performance. However, this comes at the cost of increased memory usage and requires restarting the
65+
PHP engine for changes to take effect.
66+
67+
.. note:: If you want to use `Preloading <https://www.php.net/manual/en/opcache.preloading.php>`_,
68+
we provide a `preload script <https://github.com/codeigniter4/CodeIgniter4/blob/develop/preload.php>`_.
69+
70+
Requirement
71+
-----------
72+
73+
Using preloading requires one dedicated PHP handler. Normally, web servers are configured to use one PHP handler, so one app requires a dedicated web server.
74+
If you want to use preloading for multiple apps on one web server, configure your server to use virtual hosts with multiple PHP handlers like multiple PHP-FPMs, with each virtual host using one PHP handler.
75+
Preloading keeps the relevant definitions in memory by reading the files specified in ``opcache.preload``.
76+
77+
.. note:: See :ref:`running-multiple-app` to make one core CodeIgniter4 to handle your multiple apps.
78+
79+
Configuration
80+
-------------
81+
82+
Open ``php.ini`` or ``xx-opcache.ini`` if you have split INI configuration in PHP, and recommend to set ``opcache.preload=/path/to/preload.php`` and ``opcache.preload_user=myuser``.
83+
84+
.. note:: ``myuser`` is user running in your web server. If you want to find the location of the split INI configuration, just run ``php --ini`` or open file ``phpinfo()`` and search *Additional .ini files parsed*.
85+
86+
Make sure you use the appstarter installation. If using manual installation, you must change the directory in ``include`` path.
87+
88+
.. literalinclude:: preloading/001.php
6589

6690
.. _deployment-to-shared-hosting-services:
6791

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
// ...
4+
5+
class preload
6+
{
7+
/**
8+
* @var array Paths to preload.
9+
*/
10+
private array $paths = [
11+
[
12+
'include' => __DIR__ . '/system', // <== change this line to where CI is installed
13+
// ...
14+
],
15+
];
16+
17+
// ...
18+
}
19+
20+
// ...

0 commit comments

Comments
 (0)