phpargumentswkhtmltoimage

Argument list too long error for wkhtmltoimage


I want to capture the screen and store it to to the server. I have used the below command to achieve the screen capture in my php code.

$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);

When I run the above code it works fine. But when I passed huge text of values to the parameter named estr it throws error code number 127(command can not found) when i echo the value of $resCommand. And also when I try to execute the command in the putty it throws error like below,

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

Based on the above error I surfed in the internet and I got suggestion like I have to increase the ARG_MAX value. But the suggestions were not clear and vague. I could not located the argument and how to increase the value.

Kindly suggest me where and how to increase the ARG_MAX value or kindly suggest me if any other solution is available to fix this issue?.

My OS version: - 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) )

Thanks, Ravichandran


Solution

  • I am unable to test it, but I believe the below workaround should help you solve the issue. It is probably best to leave the ARG_MAX value untouched as it can have side effects.

    //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);