Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

customizable timing for paging operations #226

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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