PHPackages                             eftec/autoloadone - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. eftec/autoloadone

ActiveSoftware[Utility &amp; Helpers](/categories/utility)

eftec/autoloadone
=================

AutoloadOne is a program that generates an autoload class for PHP.

1.30.1(1y ago)403.4k12[2 issues](https://github.com/EFTEC/AutoLoadOne/issues)MITPHPPHP &gt;=7.4

Since Jun 26Pushed 1y ago4 watchersCompare

[ Source](https://github.com/EFTEC/AutoLoadOne)[ Packagist](https://packagist.org/packages/eftec/autoloadone)[ Docs](https://github.com/EFTEC/AutoLoadOne)[ RSS](/packages/eftec-autoloadone/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (10)DependenciesVersions (34)Used By (0)

PHP Auto Include AutoLoadOne Generator
======================================

[](#php-auto-include-autoloadone-generator)

AutoloadOne is a program that generates an autoload class (Auto Include) for PHP that is project specific. This class is useful to use classes on code without calling each "include" manually. It is a direct alternative to Composer's autoload, but it works differently.
Composer's autoload, scans the folders during runtime, while this library only scans the folder once, and it stores the result.

[![Packagist](https://camo.githubusercontent.com/93f441ec3841c3e954a6fab799afbc195ff127ab88b3712ce4113dca1381976c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f65667465632f6175746f6c6f61646f6e652e737667)](https://packagist.org/packages/eftec/autoloadone)[![Total Downloads](https://camo.githubusercontent.com/e40f228b5f99dd4bcc8b9e75c15979e52ff9f3c0df5e20a23461cd2ea27f587b/68747470733a2f2f706f7365722e707567782e6f72672f65667465632f6175746f6c6f61646f6e652f646f776e6c6f616473)](https://packagist.org/packages/eftec/autoloadone)![Maintenance](https://camo.githubusercontent.com/0c8f829897840ac35cb3daf181a719612c0f64c0ed5fca3c7b90ed7591169162/68747470733a2f2f696d672e736869656c64732e696f2f6d61696e74656e616e63652f7965732f323032352e737667)![composer](https://camo.githubusercontent.com/7a6cce75e3353cd615b111f2f4ff50dec30cf814dddb88b2613f656cec298330/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f6d706f7365722d253345322e302d626c75652e737667)![php](https://camo.githubusercontent.com/59558613d05bebac3748d4f75f0c94435dec5fb11d059b448c2d172e25d82120/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d372e342d677265656e2e737667)![php](https://camo.githubusercontent.com/5cd91a78fb469ca20b235b6951fb6dd77bda78ac4633eb432e93699bcb141589/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e342d677265656e2e737667)![CocoaPods](https://camo.githubusercontent.com/cbf6770c82616f6730096a6c55b94f66c9295230a11bb898ecbf201e36c6b8e7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f63732d36302532352d79656c6c6f772e737667)

Contrary to other alternatives, it supports the easiest way to autoload classes using PHP without sacrifice performance. How it works?. AutoLoadOne pre-calculates every class of a project and generates a single autoload.php (or the name indicated) file that it's ready to use. You don't need a specific folder, structure or rule to use it. Just generate the autoload file **class**, **include,** and you are ready to load any class (even classes without a namespace, classes in the namespace in different folders, multiple classes defined in a single file...).

AutoLoadOne is a replacement to Composer's Autoload, rendering obsolete the use of psr-0 or psr-4.

> **NOTE:** If you run the dev-distro, then you must exclude the example/ folder because it contains @autorun tags.

**Last Update 26 Jan, 2023**

> "Universal Autoloading classes in PHP, any class, any time!"

Table of Contents
-----------------

[](#table-of-contents)

- [PHP Auto Include AutoLoadOne Generator](#php-auto-include-autoloadone-generator)
    - [Table of Contents](#table-of-contents)
    - [How it Works?](#how-it-works)
    - [When I should re-run AutoLoadOne?](#when-i-should-re-run-autoloadone)
    - [Composer Autoload features:](#composer-autoload-features-)
    - [AutoLoadOne extended features:](#autoloadone-extended-features-)
    - [Getting started](#getting-started)
    - [Usage using the CLI](#usage-using-the-cli)
    - [Usage via code](#usage-via-code)
    - [Usage (generate code via Web)](#usage--generate-code-via-web-)
    - [Usage (via cli)](#usage--via-cli-)
    - [Usage of the generated file (autoload.php)](#usage-of-the-generated-file--autoloadphp-)
    - [Note](#note)
    - [Autorun](#autorun)
    - [Extension](#extension)
    - [Statistic and optimization](#statistic-and-optimization)
        - [How can I reduce the map?](#how-can-i-reduce-the-map)
    - [Test](#test)
        - [AutoLoadOne](#autoloadone)
        - [Optimized AutoLoadOne](#optimized-autoloadone)
        - [Composer's autoload (using optimize)](#composers-autoload--using-optimize-)
        - [Why the size matter?.](#why-the-size-matter)
        - [Lookup usage?](#lookup-usage)
            - [How many lookup are called?.](#how-many-lookup-are-called)
    - [TEST II (Magento 2.2.3)](#test-ii--magento-223-)
        - [Let's say we have 1000 concurrent users](#lets-say-we-have-1000-concurrent-users)
        - [Compression and Magento.](#compression-and-magento)
        - [Code execution.](#code-execution)
    - [Benchmark](#benchmark)
    - [Security](#security)
    - [Composer.json](#composerjson)
    - [Version](#version)
    - [Todo](#todo)

How it Works?
-------------

[](#how-it-works)

1️⃣
Run AutoLoadOne.php as CLI or as Web.
2️⃣
AutoLoadOne will generate a single file called autoload.php (or the name indicated) based in your project. For the record, it takes mere 1.5 seconds to scan WordPress and yes, it is compatible with WordPress.
3️⃣
Include the generated file (ex: autoload.php) in your project code and start using it.

When I should re-run AutoLoadOne?
---------------------------------

[](#when-i-should-re-run-autoloadone)

You don't need to run it again if you are adding a new class with the same namespace in the same folder.

Also, you could edit autoload.php manually by adding more classes and namespaces.

Or you could run AutoLoadOne.php again and replace the old generated file.

Composer Autoload features:
---------------------------

[](#composer-autoload-features)

🔲 One class per file
🔲 One Namespace per file.
🔲 The file must have a namespace.
🔲 It requires composer.
🔲 It validates the file each file the class is loaded per user.
🔲 The structure of the folders should be pre-defined.
✅ Support CLI

AutoLoadOne extended features:
------------------------------

[](#autoloadone-extended-features)

✅ One or Many classes per file.
✅ One or many namespaces per file.
✅ The file could contain optionally a namespace.
✅ It only requires PHP
✅ The folder structure and classes are validated once.
✅ If you add a class that shares a previous folder and uses the previous namespace, then you don't need to run the generator.
✅ You could use any structure of folder. It's recommended to use the same folder for the same namespace, but it's not a requisite.
✅ Support CLI and Web-UI.
✅ It doesn't require APCU, lock files or cache.
✅ It´s compatible with practically any project, including a project that uses Composer's autoload.
✅ It's compatible with PSR-0, PSR-4, and practically any specification, since you don't need to use any special configuration or standard.
✅ It allows libraries outside the project folder.
For example /someuser/myproject/ allows to include libraries from the folder /otheruser/library/
✅ It doesn't require APCU, lock files or cache.
✅ It has a minimum impact on runtime.
✅ It allows compression without impacting the runtime.

Getting started
---------------

[](#getting-started)

You could run directly AutoLoadOne.php (via web of via CLI), or you could create a file that calls it.

Usage using the CLI
-------------------

[](#usage-using-the-cli)

You must execute it in the root folder, and it will generate a file called autoload.php.

```
php AutoLoadOne.php -generate
```

> If AutoLoadOne.php is not in the same folder then you can copy it, or set the path to use it php /somefolder/AutoLoadOne.php -generate There are more commands that you can use but -generate is the basic and out-the-box experience.

Usage via code
--------------

[](#usage-via-code)

- Copy AutoLoadOne.php in the root folder (recommended) of your project
- Execute it directly or
- Create the next PHP file (in the root folder) and execute it.

```
