KoolReport's Forum

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

Get this error when follow cloud export example....... #794

Closed henry opened this topic on on Apr 11, 2019 - 24 comments

henry commented on Apr 11, 2019

Warning: file_get_contents(http://localhost/jinxiPhp/final project/koolreport/src/clients/core/KoolReport.js): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in C:\xampp\htdocs\jinxiPhp\final project\koolreport\packages\cloudexport\vendor\chromeheadlessio\php-client\src\Exporter.php on line 163 Request failed: {"error":"Failed credential!"}

David Winterburn commented on Apr 12, 2019

Hi Henry,

Would you please paste the link http://localhost/jinxiPhp/final project/koolreport/src/clients/core/KoolReport.js to your browser's address bar and let me know if the file could be retrieved or not? Thanks!

henry commented on Apr 12, 2019

this is the result

var KoolReport = KoolReport || {};
KoolReport.load = KoolReport.load || {
    scripts:[],
    scriptCallbacks:[],
    links:[],
    linkCallbacks:[],
    doneCallbacks:[],
    resources:function(resources,cb)
    {
        if(resources.js)
        {
            this.js(resources.js,cb);
        }
        if(resources.css)
        {
            this.css(resources.css);
        }
    },
    js:function(sources,cb)
    {
        var now = sources.filter(function(value){
            return typeof(value)=="string";
        });
        var next = sources.filter(function(value){
            return typeof(value)=="object";
        });
        if(next.length==0)
        {
            this.scriptCallbacks.push(cb);
            now.forEach(function(src){
                this.registerScript(src);
            }.bind(this));
        }
        else
        {
            this.scriptCallbacks.push(function(){
                this.js(next[0],cb);
            }.bind(this));
            now.forEach(function(src){
                this.registerScript(src);
            }.bind(this));
        }
        this.checkScriptsAndCallback();
    },
    registerScript:function(src)
    {
        if(typeof this.scripts[src] == "undefined")
        {
            var existedTag = false;

            if(typeof(window.jQuery)!='undefined' && src.indexOf("/jquery.min.js")>=0)
            {
                existedTag = true;
            }

            if(existedTag==false)
            {
                var onPageScripts = document.getElementsByTagName("script");
                for(var i=0;i<onPageScripts.length;i++)
                {
                    if(onPageScripts[i].attributes["src"] && onPageScripts[i].attributes["src"].value==src)
                    {
                        existedTag = true;
                        break;
                    }
                }
            }

            if(existedTag)
            {
                this.scripts[src] = 1;
            }
            else
            {
                var script = document.createElement("script");
                script.type="text/javascript";
                script.src = src;
                script.onload = this.onScriptLoaded.bind(this);
                script.onerror = this.onScriptLoaded.bind(this);
                document.head.appendChild(script);
                this.scripts[src] = 0;    
            }
        }
    },
    onScriptLoaded:function(e)
    {
        this.scripts[e.target.attributes["src"].value] = 1;
        this.checkScriptsAndCallback();
    },
    checkScriptsAndCallback:function()
    {
        var allLoaded = true;
        for(var src in this.scripts)
        {
            allLoaded &= this.scripts[src];
        }
        
        if(allLoaded)
        {
            var runCbs = this.scriptCallbacks;
            this.scriptCallbacks = [];
            runCbs.forEach(function(cb){
                if(cb)
                {
                    try{cb();}
                    catch(err){console.log(err);}    
                }
            });
            setTimeout(this.checkOnDone.bind(this),2);
        }
    },
    onDone:function(cb)
    {
        this.doneCallbacks.push(cb);
        this.checkOnDone();
    },
    checkOnDone:function()
    {
        if(this.scriptCallbacks.length==0)
        {
            var doneCbs = this.doneCallbacks;
            this.doneCallbacks = [];
            doneCbs.forEach(function(cb){
                if(cb)
                {
                    try{cb();}
                    catch(err){console.log(err);}    
                }
            });
        }
    },

    css:function(hrefs)
    {
        var now = hrefs.filter(function(href){
            return typeof(href)=="string";
        });
        var next = hrefs.filter(function(href){
            return typeof(href)=="object";
        });

        if(next.length==0)
        {
            now.forEach(function(href){
                this.registerLink(href);
            }.bind(this));
        }
        else
        {
            this.linkCallbacks.push(function(){
                this.css(next[0]);
            }.bind(this));
            now.forEach(function(href){
                this.registerLink(href);
            }.bind(this));
        }
    },

    registerLink:function(href)
    {
        if(typeof this.links[href] == "undefined")
        {
            var links = document.getElementsByTagName("link");
            var found = false;
            for(var i=0;i<links.length;i++)
            {
                if(!found && links[i].attributes["href"] && links[i].attributes["href"].value==href)
                {
                    found = true;
                    break;
                }
            }
            if(found)
            {
                this.links[href] = 1;
            }
            else
            {
                var link = document.createElement("link");
                link.rel = 'stylesheet';
                link.type="text/css";
                link.href = href;
                link.onload = this.onLinkLoaded.bind(this);
                link.onerror = this.onLinkLoaded.bind(this);
                document.head.appendChild(link);
                this.links[href] = 0;
            }    
        }
    },
    onLinkLoaded:function(e)
    {
        this.links[e.target.attributes["href"].value] = 1;
        this.checkLinksAndCallback();
    },
    checkLinksAndCallback:function()
    {
        var allLoaded = true;
        for(var href in this.links)
        {
            allLoaded &= this.links[href];
        }
        if(allLoaded)
        {
            var runCbs = this.linkCallbacks;
            this.linkCallbacks = [];
            runCbs.forEach(function(cb){
                try{cb();}
                catch(err){console.log(err);}
            });
        }
    }
};

KoolReport.widget = (KoolReport.widget)?KoolReport.widget:{
    init:function(resources,cb)
    {
        KoolReport.load.resources(resources,cb);
    }
};
David Winterburn commented on Apr 12, 2019

Thanks, Henry. Now please create a file called test.php in your web server and put this content in:

<?php
echo file_get_contents("http://localhost/jinxiPhp/final project/koolreport/src/clients/core/KoolReport.js");

Then run the file in browser and let us now if there's any error. Thanks!

henry commented on Apr 12, 2019

hi i get this when i run test.php

var KoolReport = KoolReport || {}; KoolReport.load = KoolReport.load || { scripts:[], scriptCallbacks:[], links:[], linkCallbacks:[], doneCallbacks:[], resources:function(resources,cb) { if(resources.js) { this.js(resources.js,cb); } if(resources.css) { this.css(resources.css); } }, js:function(sources,cb) { var now = sources.filter(function(value){ return typeof(value)=="string"; }); var next = sources.filter(function(value){ return typeof(value)=="object"; }); if(next.length==0) { this.scriptCallbacks.push(cb); now.forEach(function(src){ this.registerScript(src); }.bind(this)); } else { this.scriptCallbacks.push(function(){ this.js(next[0],cb); }.bind(this)); now.forEach(function(src){ this.registerScript(src); }.bind(this)); } this.checkScriptsAndCallback(); }, registerScript:function(src) { if(typeof this.scripts[src] == "undefined") { var existedTag = false; if(typeof(window.jQuery)!='undefined' && src.indexOf("/jquery.min.js")>=0) { existedTag = true; } if(existedTag==false) { var onPageScripts = document.getElementsByTagName("script"); for(var i=0;i
David Winterburn commented on Apr 12, 2019

Hi Henry,

It seems that your path have a space character which causes the file_get_contents command to fail. Please try to change the folder "final project" to "final_project" and test cloud export again. Let us know if there's any problem.

In the near future, we will update cloud export to handle paths with space characters in them. Thanks!

henry commented on Apr 12, 2019

hi actually that is the result of folder name "finalproject", i have remove the space from 'kool report' instruction on another topic i asked

David Winterburn commented on Apr 12, 2019

Hi Henry,

What is the error now when you do cloud export? Thanks!

henry commented on Apr 12, 2019

hi i get the error as below

Warning: file_get_contents(http://localhost/jinxiPhp/finalproject/index3.php/css): failed to open stream: HTTP request failed! in C:\xampp\htdocs\jinxiPhp\finalproject\koolreport\packages\cloudexport\vendor\chromeheadlessio\php-client\src\Exporter.php on line 163

Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\jinxiPhp\finalproject\koolreport\packages\cloudexport\vendor\chromeheadlessio\php-client\src\Exporter.php on line 163
David Winterburn commented on Apr 12, 2019

Hi Henry,

Please increase your php's max timeout to around 300 seconds (in php.ini), restart apache and see if it solves the export problem. Thanks!

henry commented on Apr 12, 2019

hi i have change the max_execution_time in php.ini to 300 second and restart apache server, now i get this error

Warning: file_get_contents(http://localhost/jinxiPhp/finalproject/index3.php/css): failed to open stream: HTTP request failed! in C:\xampp\htdocs\jinxiPhp\finalproject\koolreport\packages\cloudexport\vendor\chromeheadlessio\php-client\src\Exporter.php on line 163

Warning: file_get_contents(http://localhost/jinxiPhp/finalproject/koolreport/src/clients/bootstrap/js/bootstrap.min.js): failed to open stream: HTTP request failed! in C:\xampp\htdocs\jinxiPhp\finalproject\koolreport\packages\cloudexport\vendor\chromeheadlessio\php-client\src\Exporter.php on line 163

Warning: file_get_contents(http://localhost/jinxiPhp/finalproject/koolreport/src/clients/jquery/jquery.min.js): failed to open stream: HTTP request failed! in C:\xampp\htdocs\jinxiPhp\finalproject\koolreport\packages\cloudexport\vendor\chromeheadlessio\php-client\src\Exporter.php on line 163

Fatal error: Maximum execution time of 300 seconds exceeded in C:\xampp\htdocs\jinxiPhp\finalproject\koolreport\packages\cloudexport\vendor\chromeheadlessio\php-client\src\Exporter.php on line 163
David Winterburn commented on Apr 12, 2019

Thanks, Henry, for your effort! Now please open the file test.php and paste this content to it:

<?php
echo file_get_contents("http://localhost/jinxiPhp/finalproject/koolreport/src/clients/bootstrap/js/bootstrap.min.js");

Then run test.php in browser and let me know the result. Thanks!

henry commented on Apr 12, 2019

hi this is the result in test.php

/*! * Bootstrap v3.3.7 (http://getbootstrap.com) * Copyright 2011-2016 Twitter, Inc. * Licensed under the MIT license */ if("undefined"==typeof jQuery)throw new Error("Bootstrap's JavaScript requires jQuery");+function(a){"use strict";var b=a.fn.jquery.split(" ")[0].split(".");if(b[0]<2&&b[1]<9||1==b[0]&&9==b[1]&&b[2]<1||b[0]>3)
...
David Winterburn commented on Apr 12, 2019

Thanks, Henry. It's strange that file_get_contents works in test.php but not in the report. Please wait for us to find way to track down this problem. Thanks!

henry commented on Apr 12, 2019

ok thanks! i will wait for it, btw i have posted my code on question #795 yesterday. is that possible i make some mistake on my code?

David Winterburn commented on Apr 12, 2019

I've read the topic 795 as well. There seems to be no problem with your code. Tthis looks like some environment setting mismatch between the cloudexport package and your xampp. We will let you know how to solve it as soon as possible. Thanks for your great feedback!

henry commented on Apr 12, 2019

ok thanks for helping me~ i'll wait for you guys result

henry commented on Apr 14, 2019

hi any update?

henry commented on Apr 15, 2019

hi i'm sorry to disturb but really need help, any response?

David Winterburn commented on Apr 16, 2019

Hi Henry,

Sorry, we were having public holidays in the past few days! Regarding the issue, please test this for us. Please open the file packages/cloudexport/ChromeHeadlessIoService.php and replace these lines:

$this->settings = [
            'html' => $html,
            'resourcePatterns' => [
                [
                    "regex" => '~((KoolReport.load.resources|KoolReport.widget.init)\([^\)]*)["\']([^"\',\)\[\]\:]+)["\']~',
                    "replace" => "{group1}'{group3}'",
                    "urlGroup" => "{group3}"
                ]
            ]
        ];

with these:

$this->settings = [
            'html' => $html,
            'resourcePatterns' => [
                [
                    "regex" => '~((KoolReport.load.resources|KoolReport.widget.init)\([^\)]*)["\']([^"\',\)\[\]\:]+css|[^"\',\)\[\]\:]+js|css[^"\',\)\[\]\:]+|js[^"\',\)\[\]\:]+|(?![^"\',\)\[\]\:]*(css|js))[^"\',\)\[\]\:]*)["\']~',
                    "replace" => "{group1}'{group3}'",
                    "urlGroup" => "{group3}"
                ]
            ]
        ];

Then run cloud export again and send us any error/warning message if there is. Thanks!

henry commented on Apr 16, 2019

hi happy holiday! yes i already change the code follow your instruction. and i able to download, but my graph was not shown and the table has no CSS

David Winterburn commented on Apr 16, 2019

Hi Henry,

Please open packages/cloudexport/ChromeHeadlessIoService.php again and use these lines for me:

$this->settings = [
            'html' => $html,
            'resourcePatterns' => [
                [
                    "regex" => '~((KoolReport.load.resources|KoolReport.widget.init)\([^\)]*)["\']([^"\']+css|[^"\']+js|css[^"\']+|js[^"\']+|(?![^"\',\)\[\]\:]*(css|js))[^"\',\)\[\]\:]*)["\']~',
                    "replace" => "{group1}'{group3}'",
                    "urlGroup" => "{group3}"
                ]
            ]
        ];

Let me know the result. Thanks!

henry commented on Apr 16, 2019

hi thanks for your help, its work !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! thank you love you guys so much !

Aris PeWe commented on Aug 2, 2020

Helloo i got error while running pdf cloud export with chromeheadlessio in laravel

ErrorException …\vendor\chromeheadlessio\php-client\src\Exporter.php : line 323

"file_get_contents(): Filename cannot be empty"

David Winterburn commented on Aug 3, 2020

Hi,

Please open a new topic for your issue with your CloudExport package version, setup's and export's php code, screenshot of errors, etc. 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
solved

CloudExport