Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines
Thanks for the reply, I am using PHP added and followed the guide for the export package. https://www.koolreport.com/docs/export/overview/
In my controller, I have added,
$report ->run() ->export($reports['source'].'Pdf')->pdf()->toBrowser($reports['source'].'.pdf');
I was getting the pdf blank, now when adding the phantomjs got this error above.
Thanks in advance
changed my code to:
$phantomjs_path = public_path("\plugins\koolreport\\export\bin");
$report
->run()
->export($reports['source'].'Pdf')
->settings(array(
"phantomjs"=>$phantomjs_path
))
->pdf()
->toBrowser($reports['source'].'.pdf');
now getting the following error:
Error! Could not execute phantomjs
please any advice for this one...
If you go to the line 52 of koolreport/export/Handler.php, you will see this:
if (!is_executable($this->phantomjs)) {
throw new \Exception("Please set executable permission for phantomjs");
}
In here we try to check if the phantomjs has permission to run or in another word, if it is executable. If you have set the permission for phantomjs.exe in bin folder, please comment those above line to bypass the permission checking. Let us know if it works.
The error:
AH01071: Got error 'PHP message: PHP Fatal error: Uncaught Exception: Could not execute phantomjs in /APT_KoolReport/vendor/koolreport/export/Handler.php:68\nStack trace:\n#0 /APT_KoolReport/vendor/koolreport/export/Handler.php(274): koolreport\export\Handler->runPhantom()\n#1 /APT_KoolReport/report/1.1.1/export_pdf.php(8): koolreport\export\Handler->pdf()\n#2 {main}\n thrown in /APT_KoolReport/vendor/koolreport/export/Handler.php on line 68', referer: /APT_KoolReport/report/1.1.1/Report_1.1.1.php
My code:
<?php
require_once "Report_1_1_1.php";
$report = new Report_1_1_1;
$report->run()
->export('Report_1_1_1_pdf')
->pdf(array(
"format"=>"A4",
"orientation"=>"landscape",
"zoom"=>"0.8",
"margin"=>"0.5in"
))
->toBrowser("Report_1.1.1.pdf", true);
Pls try to run a standard example in the following link with your `koolreport/export/bin/phantomjs' file:
https://phantomjs.org/screen-capture.html
Let us know the result. Tks,
Don't replace the GitHub link with your report one. We are trying to evaluate PhantomJS first. Create the Github.js file and a phantomjs.php file with this content:
<?php
//phantomjs.php
shell_exec("phantomjs github.js");
Put both of these file in koolreport/export/bin
and open phantomjs.php on your browser. Then see if there's a github.png image file created or there's any error message.
I ran the test the github.png image is downloaded correctly and I just get a warning:
AH01071: Got error 'PHP message: PHP Warning: Use of undefined constant \xe2\x80\x98after_setup_theme\xe2\x80\x99 - assumed '\xe2\x80\x98after_setup_theme\xe2\x80\x99' (this will throw an Error in a future version of PHP) in /var/www/vhosts/.../.../wp-content/plugins/types-custom/types.php on line 29PHP message: PHP Warning: Use of undefined constant \xe2\x80\x98macchine_plugin_setup\xe2\x80\x99 - assumed '\xe2\x80\x98macchine_plugin_setup\xe2\x80\x99' (this will throw an Error in a future version of PHP) in /var/www/vhosts/.../.../wp-content/plugins/types-custom/types.php on line 29', referer: .../vendor/koolreport/export/bin/phantomjs.php
Pls open the file koolreport/export/Handler.php
and find the following line:
$command = $this->phantomjs." --ignore-ssl-errors=true $script $source $output $params";
Add the following command right after it:
$command = $this->phantomjs." --ignore-ssl-errors=true $script $source $output $params";
echo "command = $command"; exit;
run your report export to see this command echoed. Then copy and paste it to your command line/terminal and run to see if there's any error.
Is "Report_1_1_1_pdf" your pdf view, i.e there exists the file "Report_1_1_1_pdf.view.php"? Normally we use the following files: "MyReport.php" as setup file, "MyReport.view.php" as web view file, "MyReportPDF.view.php" as pdf view file. Then we use this export command:
$report->run()->export("MyReportPDF") //this should be the file name without the ".view.php" part
->settings([
'useLocalTempFolder' => true,
'autoDeleteLocalTempFile' => true,
])
->pdf(array(...))
->toBrowser("MyReport.pdf")
;
If your pdf view file is correct, pls try to use a local temp folder setting like in my code to see if it works.
yes the file Report_1_1_1_pdf.view.php exists in the folder, on my windows pc everything works correctly, on the server instead I always get the same error
AH01071: Got error 'PHP message: PHP Fatal error: Uncaught Exception: Could not execute phantomjs in .../vendor/koolreport/export/Handler.php:69\nStack trace:\n#0
also with the following code:
<? php
require_once "Report_1_1_1.php";
$ report = new Report_1_1_1;
$ report-> run ()
-> export ('Report_1_1_1_pdf')
-> settings ([
'useLocalTempFolder' => true,
'autoDeleteLocalTempFile' => true,
])
-> pdf (array (
"format" => "A4",
"orientation" => "landscape",
"zoom" => "0.8",
"margin" => "0.5in"
))
-> toBrowser ("Report_1.1.1.pdf", true);
Pls remove auto delete local temp file setting:
-> settings ([
'useLocalTempFolder' => true,
// 'autoDeleteLocalTempFile' => true, comment out this line
])
Then echo the phantomjs command in koolreport/export/Handlers.php
:
$command = $this->phantomjs." --ignore-ssl-errors=true $script $source $output $params";
echo "command = $command"; exit;
Finally run your report export and copy the echoed phantomjs command to terminal and let us know the result. Tks,
I don't have an ' o " in command, what am I doing wrong?
php -r 'shell_exec("{phantomjs --ignore-ssl-errors=true /var/www/vhosts/domain-name/subdomain-name/APT_KoolReport/vendor/koolreport/export/pdf/pdf.js /var/www/vhosts/domain-name/subdomain-name/APT_KoolReport/report/1.1.1/tmp/615ef384af06d1.tmp /var/www/vhosts/domain-name/subdomain-name/APT_KoolReport/report/1.1.1/tmp/615ef384af1b52.pdf eyJmb3JtYXQiOiJBNCIsIm9yaWVudGF0aW9uIjoibGFuZHNjYXBlIiwiem9vbSI6IjAuOCIsIm1hcmdpbiI6IjAuNWluIiwiZXhwZWN0ZWRMb2NhdGlvbiI6Imh0dHBzOlwvXC93cC5hcHRiYXNpbGljYXRhLml0XC9BUFRfS29vbFJlcG9ydFwvcmVwb3J0XC8xLjEuMVwvZXhwb3J0X3BkZi5waHAiLCJyZXNvdXJjZVdhaXRpbmciOjEwMDB9}")';
Oh, I can see that you don't replace the curly braces in {echoed phantomjs command}. The syntax should not be:
php -r 'shell_exec("{phantomjs ...}")'
It should be:
php -r 'shell_exec("phantomjs --ignore-ssl-errors=true /var/www/vhosts/domain-name/subdomain-name/APT_KoolReport/vendor/koolreport/export/pdf/pdf.js /var/www/vhosts/domain-name/subdomain-name/APT_KoolReport/report/1.1.1/tmp/615ef384af06d1.tmp /var/www/vhosts/domain-name/subdomain-name/APT_KoolReport/report/1.1.1/tmp/615ef384af1b52.pdf eyJmb3JtYXQiOiJBNCIsIm9yaWVudGF0aW9uIjoibGFuZHNjYXBlIiwiem9vbSI6IjAuOCIsIm1hcmdpbiI6IjAuNWluIiwiZXhwZWN0ZWRMb2NhdGlvbiI6Imh0dHBzOlwvXC93cC5hcHRiYXNpbGljYXRhLml0XC9BUFRfS29vbFJlcG9ydFwvcmVwb3J0XC8xLjEuMVwvZXhwb3J0X3BkZi5waHAiLCJyZXNvdXJjZVdhaXRpbmciOjEwMDB9");'
Another point is to put a semicolon at the end of the the string. Pls try this command with no curly braces in the shell command and an added semicolon at the end (just before the last single quote):
php -r 'shell_exec("phantomjs ...");'
Pls find out which PHP user your web server run as with this php page:
<?php
echo exec('whoami');
?>
Then try to run the phantomjs command as that user. For example with runuser command or any other way:
runuser -l php_user -c ' php -r \'shell_exec("phantomjs ...");\' '
Hi Sebastian, we already ran the command with that user, the problem is to understand why from the command line now it always produces the .pdf in tmp folder, but when exporting from the php page it is not executed and always returns the error
AH01071: Got error 'PHP message: PHP Fatal error: Uncaught Exception: Could not execute phantomjs in
The most likely reason is that your terminal user is different from your php user (which user web server uses to process php). You already know which terminal user you are using. That's why I asked you to open a php page with this content:
<?php
echo exec('whoami');
?>
Then we can try to run the phantomjs command from terminal with the php user to see why it failed.
executing the command with the user:
runuser -l php_user -c ' php -r \'shell_exec("phantomjs --ignore-ssl-errors=true /var/www/vhosts/domain_name/subdomain_name/APT_KoolReport/vendor/koolreport/export/pdf/pdf.js /tmp/6167dd3c62ac01.tmp /tmp/6167dd3c62bad2.pdf eyJmb3JtYXQiOiJBNCIsIm9yaWVudGF0aW9uIjoibGFuZHNjYXBlIiwiem9vbSI6IjAuNTUiLCJtYXJnaW4iOnsidG9wIjoiMC4yaW4iLCJib3R0b20iOiIwLjJpbiIsImxlZnQiOiIyaW4iLCJyaWdodCI6IjJpbiJ9LCJleHBlY3RlZExvY2F0aW9uIjoiaHR0cHM6XC9cL3dwLmFwdGJhc2lsaWNhdGEuaXRcL0FQVF9Lb29sUmVwb3J0XC9yZXBvcnRcLzEuMi4xXC9leHBvcnRfcGRmLnBocCIsInJlc291cmNlV2FpdGluZyI6MTAwMH0=");\' '
I get from the print it returns me this error:
-bash: syntax error near unexpected token `('
where am I wrong?
Ok, you can try to switch to your php_user in terminal like this:
su - php_user
After switching run whoami to check if terminal user is switched:
whoami
Finally run the phantomjs command to see if there's any problem with running phantomjs with the switched user
phantomjs ...
I tried to insert this code in Handler.php:
$command = $this->phantomjs." --ignore-ssl-errors=true $script $source $output $params";
// echo "command = <br>" . str_replace(" ", "<br>", $command) . "<br>"; exit;
// echo "command = $command"; exit;
$dir = '../../../report/1.1.1/tmp';
// try to create this directory if it doesn't exist
$booExists = is_dir($dir) || (mkdir($dir, 0774, true) && is_dir($dir));
$booIsWritable = false;
if ($booExists && is_writable($dir)) {
$tempFile = tempnam($dir, 'tmp');
if ($tempFile !== false) {
$res = file_put_contents($tempFile, 'test');
$booIsWritable = $res !== false;
@unlink($tempFile);
}
}
the tmp folder and the temporary file are created but not the .pdf
I understand your frustration. All signs point to insufficient permission to either execute Phantomjs or writable tmp directory but your tests show that your php user has those rights when executing in command line, just not when executing via web server.
Now this is not a good advice for a production system but for debugging purpose I would suggest trying to change your Apache's php user and group to ones with admin rights:
https://www.simplified.guide/apache/change-user-and-group
Then try to run report export via browser to see how it works. Our next step depends on whether this test runs successfully or not.
Let KoolReport help you to make great reports. It's free & open-source released under MIT license.
Download KoolReport View demo