John Davidson

php - require vendor/autoload taking 14 seconds

0 comments
Message:


In our development teams, a decision has been made to not use composer (Not sure why yet). So whenever we want to use a package from 3rd party, we just use composer but copy and paste the files manually into our workspace. So in other words, we never deploy our application using composer install or composer update. Now I have installed a package called pusher using composer require pusher/pusher-php-server


My issue is that I'm not sure how to use the files since there is no composer autoload. My only solution was to require the autoload include EXTENSIONS_PATH.'/pusher/vendor/autoload.php';


However I found that whenever I call the file that includes the autoload, it takes around 14 seconds to load.
We are using php with yii.


Another solution was to use this at the beginning of the application


Yii::registerAutoloader(
function () {
require_once EXTENSIONS_PATH.'/pusher/vendor/autoload.php';
}
);

Using the above made it work in 200ms, however it conflicted with google API package that was installed in a similar manner and using similar Guzzle dependencies but with versions. If I put that piece of code just before I want to use pusher, the same 14 seconds happens.


Any help is appreciated. This is driving me crazy, and please do not close the question.



My Answer:
It seems like the issue is related to the autoloading mechanism and the conflicting dependencies between the different packages you are using. One possible solution could be to manually include the necessary files from the Pusher package in your code instead of relying on the autoload file.

You can try something like this:

php
require_once EXTENSIONS_PATH.'/pusher/src/Pusher.php';
require_once EXTENSIONS_PATH.'/pusher/src/PusherException.php';
// Include other necessary files from the Pusher package

// Now you can use the Pusher package classes directly in your code
$pusher = new Pusher\Pusher('APP_KEY', 'APP_SECRET', 'APP_ID');


By manually including the necessary files, you can avoid the overhead of the autoload mechanism and potentially reduce the loading time of your application. Just make sure to include all the required files from the Pusher package in the correct order.

Additionally, you may want to consider revisiting the decision to not use Composer in your development process. Composer is a widely used dependency manager for PHP projects and can greatly simplify the management of third-party packages and their dependencies. It may be worth exploring the reasons behind this decision and evaluating the benefits of using Composer in your workflow.

Rate this post

3 of 5 based on 4311 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us