Skip to content

Commit 851c949

Browse files
xuanskyerMASNathan
authored andcommitted
Add Web page timeout parameter settings (#62)
1 parent 463ba88 commit 851c949

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/Capture.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ class Capture
7070
*/
7171
protected $userAgentString = '';
7272

73+
/**
74+
* Sets the timeout period
75+
* @var int
76+
*/
77+
protected $resourceTimeout = 0;
78+
7379
/**
7480
* Bin directory, should contain the phantomjs file, otherwise it won't work
7581
*
@@ -145,6 +151,10 @@ public function save($imageLocation, $deleteFileIfExists = true)
145151
$data['userAgent'] = $this->userAgentString;
146152
}
147153

154+
if ($this->resourceTimeout) {
155+
$data['resourceTimeout'] = $this->resourceTimeout;
156+
}
157+
148158
if ($deleteFileIfExists && file_exists($outputPath) && is_writable($outputPath)) {
149159
unlink($outputPath);
150160
}
@@ -344,4 +354,15 @@ public function setUserAgentString($userAgentString)
344354

345355
return $this;
346356
}
357+
358+
/**
359+
* Sets the timeout period
360+
* @param int $timeout
361+
* @return $this
362+
*/
363+
public function setResourceTimeout($timeout = 30000)
364+
{
365+
$this->resourceTimeout = $timeout;
366+
return $this;
367+
}
347368
}

templates/screen-capture.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
page.clipRect = <?php echo json_encode($clipOptions) ?>;
1111
<?php endif ?>
1212

13+
<?php if (isset($resourceTimeout)) : ?>
14+
page.settings.resourceTimeout = '<?php echo $resourceTimeout ?>';
15+
<?php endif ?>
16+
1317
page.open('<?php echo $url ?>', function () {
1418
/* This will set the page background color white */
1519
<?php if (isset($backgroundColor)) : ?>

0 commit comments

Comments
 (0)