3

我想捕获屏幕并将其存储到服务器。我已经使用下面的命令在我的 php 代码中实现了屏幕截图。

$exec_command = "wkhtmltoimage --quality 10 --window-status 'wbcaptureready' --width 1200 --post 'estr' 
'JTNDVFZXQiUzRSUzQ3diJTIwc0lkJTNEJTIyd2I3NzYyNzVpeWFma3hya3Qy9UVldCJTNF' --post 'ispagehasdocument' '0' --height 1260 --enable-plugins --no-stop-slow-scripts https://example.org/page/capture/ '/data/screencapture/data/1234/1256/screenshots/screenshots/wbPage_^{4BEFBE59-EF14-4de4-9D08-3267BB76D8EA^}_0.png'";
$output = system($exec_command, $resCommand);

当我运行上面的代码时,它工作正常。但是当我将大量的值文本传递给名为estr它的参数时,当我回显$resCommand. 而且当我尝试在腻子中执行命令时,它会引发如下错误,

-bash: /usr/bin/wkhtmltoimage: Argument list too long

基于上述错误,我在网上冲浪,我得到了一些建议,比如我必须增加ARG_MAX价值。但这些建议并不明确和模糊。我找不到论点以及如何增加价值。

请建议我在哪里以及如何增加ARG_MAX价值,或者如果有任何其他解决方案可以解决此问题,请建议我?

我的操作系统版本:-Linux version 2.6.32-696.6.3.el6.x86_64 (mockbuild@c1bl.rdu2.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) )

谢谢, 拉维钱德兰

4

2 回答 2

0

我无法对其进行测试,但我相信以下解决方法应该可以帮助您解决问题。最好不要更改 ARG_MAX 值,因为它可能会产生副作用。

//This value can't have any spaces and as your string is base64encoded it shouldn't be a problem in your case.
$estrVal = 'JTNDVFZXQiUzRSUzQ3diJTIwc0lkJTNEJTIyd2I3NzYyNzVpeWFma3hya3Qy9UVldCJTNF';
//You can also create a unique file name instead of estr.txt & may be delete it later if not needed.
$estrFile = './path/to/estr.txt'; 
file_put_contents($estrFile, $estrVal);

$exec_command = "wkhtmltoimage --quality 10 --window-status 'wbcaptureready' --width 1200 --post 'estr' \"$(< ./path/to/estr.txt)\"
 --post 'ispagehasdocument' '0' --height 1260 --enable-plugins --no-stop-slow-scripts https://example.org/page/capture/ '/data/screencapture/data/1234/1256/screenshots/screenshots/wbPage_^{4BEFBE59-EF14-4de4-9D08-3267BB76D8EA^}_0.png'";

$output = system($exec_command, $resCommand);
于 2019-07-11T13:31:44.187 回答
0

我建议你像下面这样运行它


$exec_command = "ulimit -s 65535 && wkhtmltoimage --quality 10 --window-status 'wbcaptureready' --width 1200 --post 'estr' 
'JTNDVFZXQiUzRSUzQ3diJTIwc0lkJTNEJTIyd2I3NzYyNzVpeWFma3hya3Qy9UVldCJTNF' --post 'ispagehasdocument' '0' --height 1260 --enable-plugins --no-stop-slow-scripts https://example.org/page/capture/ '/data/screencapture/data/1234/1256/screenshots/screenshots/wbPage_^{4BEFBE59-EF14-4de4-9D08-3267BB76D8EA^}_0.png'";
$output = system($exec_command, $resCommand);

这可能会为您增加参数列表的大小

php > $output = system("getconf ARG_MAX", $resCommand);
2097152
php > $output = system("ulimit -s 65535 && getconf ARG_MAX", $resCommand);
16776960
于 2019-07-12T07:51:36.863 回答