From 3e20423d4d631f7f6ca48ca9f33b629fcca6a11b Mon Sep 17 00:00:00 2001 From: "Rachmatullah, Agro" Date: Sun, 26 Nov 2017 14:04:52 +0900 Subject: [PATCH] customizable timing for paging operations --- src/InstagramScraper/Instagram.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/InstagramScraper/Instagram.php b/src/InstagramScraper/Instagram.php index 22d7acfa..4b2f8b5b 100644 --- a/src/InstagramScraper/Instagram.php +++ b/src/InstagramScraper/Instagram.php @@ -20,12 +20,19 @@ class Instagram const HTTP_OK = 200; const MAX_COMMENTS_PER_REQUEST = 300; const MAX_LIKES_PER_REQUEST = 300; + const PAGING_TIME_LIMIT_SEC = 1800; // 30 mins time limit on operations that require multiple requests + const PAGING_DELAY_MINIMUM_MICROSEC = 1000000; // 1 sec min delay to simulate browser + const PAGING_DELAY_MAXIMUM_MICROSEC = 3000000; // 3 sec max delay to simulate browser private static $instanceCache; private $sessionUsername; private $sessionPassword; private $userSession; + public $pagingTimeLimitSec = self::PAGING_TIME_LIMIT_SEC; + public $pagingDelayMinimumMicrosec = self::PAGING_DELAY_MINIMUM_MICROSEC; + public $pagingDelayMaximumMicrosec = self::PAGING_DELAY_MAXIMUM_MICROSEC; + /** * @param string $username * @param string $password @@ -781,7 +788,7 @@ public function getLocationById($facebookLocationId) public function getFollowers($accountId, $count = 20, $pageSize = 20, $delayed = true) { if ($delayed) { - set_time_limit(1800); // 30 mins + set_time_limit($this->pagingTimeLimitSec); } $index = 0; @@ -827,7 +834,7 @@ public function getFollowers($accountId, $count = 20, $pageSize = 20, $delayed = if ($delayed) { // Random wait between 1 and 3 sec to mimic browser - $microsec = rand(1000000, 3000000); + $microsec = rand($this->pagingDelayMinimumMicrosec, $this->pagingDelayMaximumMicrosec); usleep($microsec); } } @@ -846,7 +853,7 @@ public function getFollowers($accountId, $count = 20, $pageSize = 20, $delayed = public function getFollowing($accountId, $count = 20, $pageSize = 20, $delayed = true) { if ($delayed) { - set_time_limit(1800); // 30 mins + set_time_limit($this->pagingTimeLimitSec); } $index = 0; @@ -892,7 +899,7 @@ public function getFollowing($accountId, $count = 20, $pageSize = 20, $delayed = if ($delayed) { // Random wait between 1 and 3 sec to mimic browser - $microsec = rand(1000000, 3000000); + $microsec = rand($this->pagingDelayMinimumMicrosec, $this->pagingDelayMaximumMicrosec); usleep($microsec); } }