Skip to content

Commit

Permalink
customizable timing for paging operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Rachmatullah, Agro committed Nov 26, 2017
1 parent 3172fa8 commit 3e20423
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/InstagramScraper/Instagram.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 3e20423

Please sign in to comment.