postaddictme / instagram-php-scraper

Get account information, photos, videos, stories and comments.
https://packagist.org/packages/raiym/instagram-php-scraper
MIT License
3.1k stars 800 forks source link

Calling many times CacheManager::getInstance() #184

Closed jakerator closed 5 years ago

jakerator commented 7 years ago

When calling getPaginateMediasByTag too often (4-5 times a minute), I'm getting this error:

"[ErrorException] [Files] Calling many times CacheManager::getInstance() for already instanced drivers is a bad practice and have a significant impact on performances. See https://github.com/PHPSocialNetwork/phpfastcache/wiki/[V5]-Why-calling-getInstance%28%29-each-time-is-a-bad-practice-%3F "

Is this some config issue? How to fix it?

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

pckz commented 5 years ago

Same for me

In CacheManager.php line 119:

[Files] Calling many times CacheManager::getInstance() for already instanced drivers is a bad practice and have a significant impact on performances.
See https://github.com/PHPSocialNetwork/phpfastcache/wiki/[V5]-Why-calling-getInstance%28%29-each-time-is-a-bad-practice-%3F

I saw that multiple users has the same problem with this lib, and anyone has been able to fix it :(

adgray commented 5 years ago

In InstagramScraper.php, change private static $instanceCache; to private static $instanceCache = null; Then, in public static function withCredentials(), change: static::$instanceCache = CacheManager::getInstance('files'); to

if (static::$instanceCache == null) {
    static::$instanceCache = CacheManager::getInstance('files');
}
pckz commented 5 years ago

@adgray worked! thanks!

Just one thing, is not InstagramScraper.php file, is Instagram.php

vendor/raiym/instagram-php-scraper/src/Instagram.php

Jurigag commented 5 years ago

Why this was never fixed?