KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

CloudExport: file_get_contents(...KoolReport.js): failed to open stream: HTTP request failed! #1044

Open Michael Ikhane opened this topic on on Aug 15, 2019 - 23 comments

Michael Ikhane commented on Aug 15, 2019

Hi,

I am trying the Cloud export and I get the error below. The URL opens on the browsers.

file_get_contents(http://127.0.0.1:8000/koolreport_assets/1456728473/KoolReport.js): failed to open stream: HTTP request failed!
David Winterburn commented on Aug 16, 2019

Hi Michael,

Is it the SakilaRental report you were talking about? Would you please post your export php code for us to check it for you? Thanks!

Michael Ikhane commented on Aug 16, 2019

No, its my own report:

ComplaintsbyCompanyType.php

class ComplaintsbyCompanyType extends \koolreport\KoolReport
{
    use \koolreport\laravel\Friendship;
    use \koolreport\bootstrap4\Theme;

    //Register cloud export service in your report
    use \koolreport\cloudexport\Exportable;


    function setup()
    { 
......

ComplaintsbyCompanyTypePDF.view.php

<?php
use \koolreport\widgets\koolphp\Table;
use \koolreport\widgets\google\BarChart;
?>
<html>
<body style="margin:0.5in 1in 0.5in 1in">
        <link rel="stylesheet" href="../../../assets/bs3/bootstrap.min.css" />
        <link rel="stylesheet" href="../../../assets/bs3/bootstrap-theme.min.css" />
        <div class="page-header" style="text-align:right"><i>Complaints Analysis By Company Type</i></div>
        <div class="page-footer" style="text-align:right">{pageNum}</div>
        <div class="container">

        <div class="row"><br/></div>
        <div class="row">
            <div class="col-md-12 text-center">
                <h3>Complaints Analysis By Company Type</h3>
                <h4><?php echo "{$this->params['quarter']}, {$this->params['year']}" ?></h4>
            </div>
        </div>
.....

ReportController.php:

public function kool() {
        $report = new ComplaintsbyCompanyType(['quarter' => 'Q3', 'year' => 2018]);
        $report->run()
        ->cloudExport("ComplaintsbyCompanyTypePDF")
        ->chromeHeadlessio("6320572b6de053c90f8c5d68afa96f08718a92f548a95602890479e4579904ab") 
        ->pdf()
        ->toBrowser("ComplaintsbyCompanyType.pdf"); 
David Winterburn commented on Aug 16, 2019

Hi Michael,

Does your report show correctly on browser? If it does, please inspect the page with F12 and find the script tag with src to koolreport.js and let us know the src path. Thanks!

Michael Ikhane commented on Aug 16, 2019

Hello David, yes it does.

David Winterburn commented on Aug 16, 2019

Thanks, Michael! Now please add the following line to your report's view file:

<?php echo file_get_contents("http://127.0.0.1:8000/koolreport_assets/1456728473/KoolReport.js"); ?>

Then open the report on browser and let us know the result. Thanks!

Michael Ikhane commented on Aug 16, 2019

file_get_contents(http://127.0.0.1:8000/koolreport_assets/1456728473/KoolReport.js): failed to open stream: HTTP request failed!

David Winterburn commented on Aug 16, 2019

Hi Michael,

Would you please check your php.ini file for the following option: allow_url_fopen?

If it's not there or off please set: allow_url_fopen=On

Then try cloudexport again and let us know the result. Thanks!

Michael Ikhane commented on Aug 16, 2019

It is on

David Winterburn commented on Aug 16, 2019

Thanks, Michael. It's such a strange issue. Would you please open php.ini again and add/uncomment this line:

user_agent="PHP"

Then try file_get_contents again. Thanks!

Michael Ikhane commented on Aug 16, 2019

This works: <?php echo file_get_contents("https://google.com"); ?>

David Winterburn commented on Aug 16, 2019

So the problem is perhaps with your localhost server closing connection of file_get_contents. Please try the user_agent="PHP" option in my previous post and let me know the result. Thanks!

Michael Ikhane commented on Aug 16, 2019

I have found the problem. I was using the Laravel built-in server (php artisan serve). So I switched to my XAMPP (http://localhost/port-transport-api/public/api/auth/reports/kool).

But now I am getting: mkdir(): Permission denied

/Applications/XAMPP/xamppfiles/htdocs/port-transport-api/vendor/chromeheadlessio/php-client/src/Exporter.php:

    $relativePath = substr($filePath, strlen($rootPath) + 1);
 
                // Add current file to archive
                $zip->addFile($filePath, $relativePath);
            }
        }
 
        // Zip archive will be created only after closing object
        $zip->close();
    }
 
    function saveTempContent($content)
    {
        $settings = $this->settings;
        $tmpFolder = $this->getTempFolder();
        $tempDirName = uniqid();
        $tempZipName = $tempDirName . ".zip";
        $tempZipPath = $tmpFolder . "/" . $tempZipName;
        $tempPath = $tmpFolder . "/" . $tempDirName;
        mkdir($tempPath);
....
David Winterburn commented on Aug 16, 2019

Hi Michael,

Is it possible to set write access of your system temporary folder for php user of XAMPP?

Michael Ikhane commented on Aug 16, 2019

ok. i will try that.

Thanks

David Winterburn commented on Aug 16, 2019

Another option is to update cloudexport package to version 1.5.0 with composer and use the following setting:

    $report->run()
    ->cloudExport("MyReportPdf")
    ->chromeHeadlessio($secretToken)
    ->settings([
        'useLocalTempFolder' => true
    ])
    ->pdf($pdfOptions)
    ->toBrowser($filename)
    ;
Michael Ikhane commented on Aug 16, 2019

Thanks, but that didnt work because of this function in /vendor/chromeheadlessio/php-client/src/Exporter.php:

function getTempFolder()
    {
        // if($useLocalTempFolder)
        // {
        //     if(!is_dir(realpath(dirname(__FILE__))."/tmp"))
        //     {
        //         mkdir(realpath(dirname(__FILE__))."/tmp");
        //     }
        //     return realpath(dirname(__FILE__))."/tmp";
        // }
        return sys_get_temp_dir();
    }

So I replaced the above function with this, and set the tmp folder permission to 777, and it worked:

    function getTempFolder()
    {
            if(!is_dir(realpath(dirname(__FILE__))."/tmp"))
            {
                mkdir(realpath(dirname(__FILE__))."/tmp");
            }
            return realpath(dirname(__FILE__))."/tmp";
    }

Please, is there a way to clear the tmp folder, I can imagine it building up over time.

David Winterburn commented on Aug 19, 2019

Hi Micheal,

Please run composer update for the cloudexport package. In the latest php-client update we have added the "useLocalTempFolder" option. Thanks!

Michael Ikhane commented on Aug 19, 2019

Hello David,

The cloudexport package isnt updating. Composer says "Nothing to install or update"

Thanks

David Winterburn commented on Aug 19, 2019

Hi Michael,

Please delete the folder koolreport/cloudexport and run these commands:

composer clear-cache

composer update

Please make sure the version of koolreport/cloudexport is 1.5.0 and that of chromeheadlessio/php-client is 0.3.2. Thanks!

Michael Ikhane commented on Aug 19, 2019

composer.json:

...... "koolreport/cloudexport": "^1.5.0", ......

Error:

Your requirements could not be resolved to an installable set of packages.

Problem 1

- koolreport/pro 4.1.2 requires koolreport/cloudexport 1.4.0 -> satisfiable by koolreport/cloudexport[1.4.0] but these conflict with your requirements or minimum-stability.
David Winterburn commented on Aug 20, 2019

Please try to run this command:

composer require koolreport/cloudexport:1.5.0

Thanks!

Michael Ikhane commented on Aug 20, 2019

Please, can you send me a zip of the affected packages? I still could not install.

$ composer require koolreport/cloudexport:1.5.0

./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - koolreport/pro 4.1.2 requires koolreport/cloudexport 1.4.0 -> satisfiable by koolreport/cloudexport[1.4.0] but these conflict with your requirements or minimum-stability.
    - koolreport/pro 4.1.2 requires koolreport/cloudexport 1.4.0 -> satisfiable by koolreport/cloudexport[1.4.0] but these conflict with your requirements or minimum-stability.
    - koolreport/pro 4.1.2 requires koolreport/cloudexport 1.4.0 -> satisfiable by koolreport/cloudexport[1.4.0] but these conflict with your requirements or minimum-stability.
    - Installation request for koolreport/pro (locked at 4.1.2, required as *) -> satisfiable by koolreport/pro[4.1.2].


David Winterburn commented on Aug 20, 2019

Hi Michael,

Please open the file: koolreport\pro\composer.json and change the following line:

"koolreport/cloudexport": "1.4.0",

to:

"koolreport/cloudexport": "1.5.*",

Then try composer update again and let us know the result. Thanks!

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

CloudExport