Download the PHP package eftec/autoloadone without Composer

On this page you can find all versions of the php package eftec/autoloadone. 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 autoloadone

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 Total Downloads [Maintenance]() [composer]() [php]() [php]() [CocoaPods]()

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

How it Works?

:one:
Run AutoLoadOne.php as CLI or as Web.
:two:
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.
:three:
Include the generated file (ex: autoload.php) in your project code and start using it.

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:

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

AutoLoadOne extended features:

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

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

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

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 (generate code via Web)

:one:
Copy the file autoloadone.php somewhere.

:two:
For security, you could edit the first lines of the class autoloadone.php. Change the user, password and autoloadenter if it's required.

:three:
Start the browser

Enter your user and password. If _AUTOLOAD_ENTER is true then you are logged automatically.

autoloadone login

:four:
Select the folder to scan, then select the file to generate and finally press the button GENERATE.

autoloadone screen

:five:
The result should look this:

autoloadone screen2

Usage (via cli)

autoloadone cli

In the shell, browser to the folder where you want to generate the code and run the next command

Commands available :

Example: php autoloadone.php -folder folder\scan -filegen folder\whereautoload\ -save yes

Usage of the generated file (autoload.php)

:one:
include the generated file by the previous step. ex: autoload.php

and that's it!.

In the /test folder you could find some example to try.

Note:Finally, you could delete the file autoloadone.php if you wish for.

Note

If you want to exclude a class, you could add the namespace to the exclude list, or you could skip a folder.
Also, if a class has the next comment, it's excluded automatically:

Autorun

If you want to execute (run) a php file, then you could add the next comment.

You could also set priority to the execution by adding a comment with @autorun first

If you find the error: Parse error: syntax error, in on line 000. Then some php files scanned have some syntax error. The solution is to fix the problem or to exclude the whole folder.
How to find the file with error? You could run the page with the debug flag: autoloadone.php?debug=1

Extension

You could change the extension (by default it is .php) by running the next command

Statistic and optimization

This library generates the next statistics. The objective is simple, you must reduce (in the possible), the size of the map. The smaller the map, then the better.

Example of the screen:

In the log file:

How can I reduce the map?

Test

I created an empty blog on Laravel. The project is empty but the default libraries and components.

Files:

7545 files in total. (including files that aren't PHP files)

AutoLoadOne

Number of Classes: 5565
Number of Namespaces: 765
Number of Maps: 2305 (you want to reduce it)
Number of PHP Files: 6302
Number of PHP Autorun: 0
Number of conflicts: 31

File generated:

autoload.php 231kb.

Optimized AutoLoadOne

I separated PHPUnit and Mockery from the project. Why? Both libraries are for unit test.

excluded namespace = /vendor/phpunit/,/vendor/mockery/

Number of Classes: 5565
Number of Namespaces: 765
Number of Maps: 1535 (you want to reduce it)
Number of PHP Files: 6302
Number of PHP Autorun: 0
Number of conflicts: 13     

File generated:

autoload.php 159kb.    

Composer's autoload (using optimize)

composer dump-autoload -o

Generated optimized autoload files containing 3519 classes
Number of Maps: 3519 (static and not-static)

Autoload uses one of the next methods:

Why the size matter?.

Let's say we are calling a single webpage that uses autoload.

If we use Composer's autoload (static), we are also calling a file that uses 468kb (plus other files), and this memory is loaded into the memory. It could use (an average of) 609kb of ram per call (it's around PHP file x 1.3 x 1kb)

For example, what if we have 1000 concurrent users. It will use 609kb x 1000 = 609mb of ram thanks to Autoload alone at the same time and with 10k concurrent users we will use 6gb of ram only because autoload.

With AutoLoadOne, it is optimized to 302mb (1000 users) or 3gb (10k users), it is for the version not optimized.

AutoLoadOne tags all classes from the project, including classes that aren't defined in composer.json (unless they are excluded from the project). Composer's autoload found only 3519 classes, while AutoLoadOne found all classes of the project (5565).

However, some classes are not required to be loaded by the project (for example unit test classes), so we could exclude those classes of the project.

For example, excluding PHPUnit and Mockery reduces the use to 206mb (1000 users) or 2gb (10k users) but we could optimize it even further.

Concurrent Users Composer's autoload (Optimized) AutoLoadOne AutoLoadOne Optimized AutoLoadOne Optimized and compressed
1000 609mb 301mb 206mb 130mb
10000 6gb 3gb 2gb 1gb

Lookup usage?

Let's say we have a "map" with different elements. How much time does it take to find the element of the map?.

Map size Time (1 million of lookup sequentially)
100 0.271 seconds +/-
10.000 0.299 seconds +/-
1.000.000 0.376 seconds +/-

So, the size of the map/lookup time is not important. The difference between a small map (100 elements) versus a huge map (1 million of elements) is 0.1 second in total (per 1 millon of queries). However, the memory usage matters, and it could impact the performance considerably.

How many lookup are called?.

Let's say we have 10k concurrent users and each one calls 100 different classes. It means we are doing 10k x 100 = 1 million of lookup at the same time.

TEST II (Magento 2.2.3)

Magento is a huge project, it has 22k PHP files and from it, 20k are classes.

AutoLoadOne:

Number of Classes: 21063
Number of Namespaces: 7018
Number of Maps: 9473 (you want to reduce it)
Number of PHP Files: 22862
Number of PHP Autorun: 0
Number of conflicts: 6
Ratio map per file: 41.44% Bad. (less is better. 100% means one map/one file)
Ratio map per classes: 44.97% Bad. (less is better. 100% means one map/one class)
Map size: 1398.7 kbytes (less is better, it's an estimate of the memory used by the map)
Map size Compressed: 1195.1 kbytes (less is better, it's an estimate of the memory used by the map)

It takes +/- 200 seconds to generate the autoload.php

In comparison, Composer's autoload (optimized) uses

Generated optimized autoload files containing 11582 classes
Number of Maps: 11582 classes (2.6mb of memory will be use per request per user)
Composer's autoload (optimized) AutoLoadOne (not optimized) AutoLoadOne (not optimized, compressed)
2.6mb 1.36mb 1.16mb

However, it is without a manual optimization.

Let's say we have 1000 concurrent users

Concurrent Users(*) Composer's autoload (Optimized) AutoLoadOne (not optimized) AutoLoadOne (compressed)
1000 2.6gb 1.36gb 1.16gb
10000 26gb 13.6gb 11.6gb

(*) However, Magento wasn't create for concurrency. But, however what we are measuring is not the number of concurrent users but the number of concurrent calls (for example rest-json, opening a page and such).

Compression and Magento.

While AutoLoadOne is able to compress the map, but it only compresses the path of it, not the namespace. It is because the compression is aimed to generate the minimum impact on the system. Magento relies on heavily in huge namespaces so the compression is unable to compress them. But still, the system is able to compress values in 15%.

In general, the compression allows to shrink the values in 40-50%.

Code execution.

Both AutoLoadOne and Composer's autoload execute a code when it is initialized/executed.

When AutoLoadOne generates the map, it consists of two relational arrays as follows:

While Composer's autoload generates an array that requires concatenation.

So it requires to concatenate each map (with a variable called $baseDir). So Composer's autoload affects slighly the performance.

Benchmark

PHP 7.1.18 + Windows 10 + SSD.

AutoloadOne Benchmark

More is better.

I did a synthetic benchmark by loading different classes and reading the performance of it. Since my machine has a SSD disk then, the impact of the disk is minimum in comparison with a mechanical hard disk. This chart compares the performance against INCLUDE.

Security

You could block the access to the file

RedirectMatch 403 ^/folder/^/folder/.*$

:heavy_exclamation_mark: While the program has a build-in-security measure, however I suggest to protect adding new layers of security such as locating the AutoLoadOne.php file outside the public/web folder.

AutoLoadOne.php is not safe (because it writes a generate file), it doesn't have access to the database, neither it allows to write any content to the file but, it could overwrite an exist code and put down a system.

However, the generate file is safe (autoload.php) and you could expose to the net.

Composer.json

Commonly, this library does not need composer.json, and it actively ignores its configuration (because it reads the PHP source code directly). However, since 1.19, AutoLoadOne reads (optionally) part of the information of composer.json (for compatibility purpose). For example, the library guzzlehttp uses this feature.

Note: it requires to set the constant _AUTOLOAD_COMPOSERJSON to true. By default, this variable is false.

Let's say the next file:

composer.json

If AUTOLOAD_COMPOSERJSON is true the AutoLoadOne includes the file (or files) declared in composer.json and declared in 'files'. This file or files is added to our autoload.php as follows:

Our code to generate autorun.php

And our autorun.php generated.

Since it is done once (when autoload.php is generated), then this feature does not affect the performance because it reads the composer.json files once.

Version

Todo


All versions of autoloadone with dependencies

PHP Build Version
Package Version
Requires ext-json Version *
php Version >=7.2.5
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 eftec/autoloadone contains the following files

Loading the files please wait ....