KoolReport's Forum

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

Issues using Koolreport on Laravel Vapor #1741

Closed Nicholas Savill opened this topic on on Nov 29, 2020 - 8 comments

Nicholas Savill commented on Nov 29, 2020

Hi

I am trying to deploy Koolreport to Laravel Vapor. This is an implementation of Laravel hosted in a serverless environment using AWS Lambda.

At first, when I tried running a report I got ErrorException: Undefined index: SCRIPT_NAME at /vendor/koolreport/core/src/core/Utility.php line 491. The reason was that there was no $_SERVER['SCRIPT_NAME'] variable defined in the environment. As a workaraound, I am running the following code prior to running the report (I might consider raising a PR for this):

    if (!array_key_exists("SCRIPT_NAME", $_SERVER)) {
      $scriptFilename = str_replace("\\","/",$_SERVER["SCRIPT_FILENAME"]);
      
      // Read script_filename backwards until we reach /
      for ($i=strlen($scriptFilename)-1; $scriptFilename[$i]!="/" && $i>0 ; $i--) {
      }

      $_SERVER["SCRIPT_NAME"] = substr($scriptFilename, $i);
    }

Having resolved that issue, I am now getting copy(/var/task/public/koolreport_assets/3157288213/KoolReport.js): failed to open stream: No such file or directory (View: /var/task/resources/views/reports/report.blade.php) at /vendor/koolreport/core/src/core/Utility.php line 92. This line is part of the Utility::recurseCopy() method and reads:

Utility::recurseCopy($src . '/' . $file, $dst . '/' . $file);

The context is

{
  dir: Resource stream, 
  dst: /var/task/public/koolreport_assets/3157288213, 
  file: KoolReport.js, 
  src: /var/task/vendor/koolreport/core/src/clients/core
}

Further investigation reveals that the folder /var/task/public/koolreport_assets/3157288213 doesn't exist, though it's parent (koolreport_assets) does (at, at the time of debugging, so was koolreport_assets/3460555030.

Is there anything that I can do prior to running the report (or ideally at deployment time) to prevent this copy from occurring? And where does the folder name 3157288213 come from?

Finally, are there any other known issues deploying to Laravel Vapor that I would need to be aware of?

Many thanks Nick

David Winterburn commented on Nov 30, 2020

Hi Nicholas,

Thanks for your feedback! We will research this issue in AWS lambda with serverless and get back to you with a solution. Thanks!

Nicholas Savill commented on Nov 30, 2020

Hi David

Thank you for your kind reply.

My gut feel tells me that the issue is connected with Laravel Vapor's implementation rather than with Lambda per se. Though I may be wrong...

Best wishes Nick

David Winterburn commented on Dec 1, 2020

Hi Nicholas,

To solve the script name issue, please open the original Utility.php and replace this line:

        $scriptFilename = str_replace("\\","/",$_SERVER["SCRIPT_FILENAME"]);

with these ones:

        $script_name = self::get($_SERVER, "SCRIPT_NAME",
            self::get($_SERVER, "REQUEST_URI",
                self::get($_SERVER, "PHP_SELF", "")));
        $script_name = strtok($script_name, '?');
        $script_name = str_replace("\\", "/", $script_name);
        $new_way = str_replace($script_name, "", $script_filename);

To find out what's wrong with the asset dorectory please open Utility.php, go to function recurseCopy and replace this line:

        @mkdir($dst);

with these one:

        error_reporting(-1);
        mkdir($dst);

I suspect that your php user doesn't have enough right to make a new directory in the asset directory. Please let us know the result. Thanks!

Nicholas Savill commented on Dec 1, 2020

Hi David

The error message from mkdir was mkdir(): Read-only file system, which is not 100% surprising.

One thing I noticed during the deployment to Vapor was that it takes a copy of /public from the local hard drive of my machine. This time, during deployment, I had 3 subfolders under koolreport_assets, namely:

$ ls -lR koolreport_assets
koolreport_assets:
total 0
drwxr-xr-x 1 nresa 197609 0 Dec  1 14:31 162342713/
drwxr-xr-x 1 nresa 197609 0 Dec  1 14:31 3157288213/
drwxr-xr-x 1 nresa 197609 0 Dec  1 14:31 417790547/

koolreport_assets/162342713:
total 13
-rw-r--r-- 1 nresa 197609  156 Dec  1 14:31 table.css
-rw-r--r-- 1 nresa 197609 8512 Dec  1 14:31 table.js

koolreport_assets/3157288213:
total 12
-rw-r--r-- 1 nresa 197609 6211 Dec  1 14:31 KoolReport.js
-rw-r--r-- 1 nresa 197609 1909 Dec  1 14:31 KoolReport.subReport.js

koolreport_assets/417790547:
total 336
-rw-r--r-- 1 nresa 197609  88147 Dec  1 14:31 jquery.min.js
-rw-r--r-- 1 nresa 197609 253681 Dec  1 14:31 jquery-ui.min.js

So, this time, there was only 1 subfolder missing.

I wonder if the solution is to build this folder during deployment rather than trying to populate it at runtime. This would also be consistent with all other front-end packages, which are built using npm.

Regards Nick

David Winterburn commented on Dec 4, 2020

Hi Nicholas,

The assets' sub directory are created one time on demand (i.e a user opens a page). So the easiest way before deployment a local source to server is to request all of your report pages either manually or programmatically. Thanks!

Nicholas Savill commented on Dec 4, 2020

Thank you David for your assistance. Having looked at this over the last several days, I think I've come to the conclusion that Koolreport is not going to work in this architecture. However, it's not the first software which struggled in the architecture. Even Laravel's own Spark package needed modifying to work there. I'm looking into migrating the project onto a more traditional LAMP stack using Laravel Forge, and feel the chances of success are much greater. Fingers crossed :-)

David Winterburn commented on Dec 8, 2020

Hi Nicholas,

It's regretting there hasn't been an easy way to deploy our report framework to Laravel server-less PHP platform like Vapor on AWS lambda. We will explore options to make KoolReport work with Laravel Vapor in the quickest way. Thanks!

Nicholas Savill commented on Dec 8, 2020

Hi David

Once again thank you very much for your help.

Since originally writing, I have investigated an alternative to KoolReport (Smart Reporting Engine - I found it to be far inferior to KoolReport and not really fit for purpose) and I have also run a proof of concept about migrating to Laravel Forge. The latter course will increase my costs but provides a number of advantages, not only that KoolReport seems to work in that environment, but also that I understand the technology far better, and that I can cut over to the new environment seamlessly from our existing implementation.

Good luck with investigating Vapor, and do keep me informed if you have any success!

Kind regards Nick

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

None