production.ERROR: PhantomJS - Invalid response

Hi there,

Im running a self hosted version of Invoice ninja and i want to use local phantomJs. I have tried to use the cloud version but have had no luck so am resorting to local generation.

The machine is a raspberry pi 3 b+

This is the error im getting…

[2019-04-01 11:26:08] production.ERROR: PhantomJS - Invalid response http://192.168.0.253/view/ueakqjpw9rr7ipk2xqnr2vi8gfzvz2pe?phantomjs=true&phantomjs_secret=wm3x0cnl4elfzxkyz6ecgy8hhnbfsxcz: {“context”:“PHP”,“user_id”:1,“account_id”:1,“user_name”:“Nick Harding”,“method”:“GET”,“user_agent”:“Mozilla/5.0 (Windows NT 6.1; WOW64; rv:66.0) Gecko/20100101 Firefox/66.0”,“locale”:“en”,“ip”:“192.168.0.6”,“count”:3,“is_console”:“no”,“is_api”:“no”,“db_server”:“mysql”,“url”:“test_headless”} []

Here is my .env file…

APP_ENV=production
APP_DEBUG=false
APP_LOCALE=en
APP_URL=http://192.168.0.253
APP_KEY=
APP_CIPHER=AES-256-CBC
REQUIRE_HTTPS=false
DB_TYPE=mysql
DB_HOST=localhost
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
MAIL_DRIVER=smtp
MAIL_PORT=587
MAIL_ENCRYPTION=tls
MAIL_HOST=smtp.gmail.com
MAIL_USERNAME=**************
MAIL_FROM_NAME=‘Harding Heating & Plumbing’
MAIL_FROM_ADDRESS=*********************
MAIL_PASSWORD=************
PHANTOMJS_BIN_PATH=/usr/bin/phantomjs
PHANTOMJS_SECRET=
MAILGUN_DOMAIN=
MAILGUN_SECRET=
GOOGLE_MAPS_API_KEY=***************

If i run which phantomjs it returns…

root@HHP-01:/var/log# which phantomjs
/usr/bin/phantomjs

Could someone please give me some ideas as i am pulling my hair out here.

Many thanks,
Nick.

Here is a little more info after running the test script…

root@HHP-01:/var/www/invoiceninja# phantomjs test.pjs
QXcbConnection: Could not connect to display
PhantomJS has crashed. Please read the bug reporting guide at
<http://phantomjs.org/bug-reporting.html> and file a bug report.
Aborted

So i realised i have to run it as screenless so i ran this command…

export QT_QPA_PLATFORM=offscreen

If i rerun the test script i get…

root@HHP-01:/var/www/invoiceninja# phantomjs test.pjs
\n{
“errorCode”: 408,
“errorString”: “Network timeout on resource.”,
“headers”: [
{
“name”: “Accept”,
“value”: “text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8”
},
{
“name”: “User-Agent”,
“value”: “Mozilla/5.0 (Unknown; Linux) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1”
}
],
“id”: 1,
“method”: “GET”,
“time”: “2019-04-01T11:48:15.004Z”,
“url”: “http://192.168.0.2/view/ueakqjpw9rr7ipk2xqnr2vi8gfzvz2pe?phantomjs=true&phantomjs_secret=wm3x0cnl4elfzxkyz6ecgy8hhnbfsxcz_”,
“status”: 408,
“console”: []
}root@HHP-01:/var/www/invoiceninja#

Looks like its holding on resources now, so need to work out how to allow more resources to it.

Not sure, maybe it’s a network/firewall issue?

Did you install from an apt repository? Those generally seem to have issues, in my experience.

Try sudo apt purge phantomjs, then drop this into /usr/bin/ and point your env file to it:

https://github.com/fg2it/phantomjs-on-raspberry/blob/master/rpi-2-3/wheezy-jessie/v2.1.1/phantomjs

It’s a stand-alone, precompiled binary of PhantomJS 2.1.1 built specifically for the ARM CPU on the Pi. Just make sure you assign it the right permissions for it to be executable system-wide.

Thanks @Titanfail for your ongoing help, looking forward to dropping PhantomJS in v2…

Hi Titanfail, thanks for your reply.

i installed phantomjs via apt-get, so i can see why this is an issue now. Would you be able to give me some instructions on how to install the file in your link? i took a look at the readme and couldnt find any helpful information.

I am slowly getting back into the coding side of things, ive always been in touch with it but ive had a few years away so having to learn it again so please bear with me.

Regards,
Nick.

No problem. Just keep in mind I haven’t tested this yet, so no guarantees (the only Pi in my house right now is a Plex client in my home theater setup).

  • Before downloading the file, make sure you use sudo apt purge phantomjs to get rid of all traces of the current install, including any dependencies that might not be needed (IIRC, the apt version installs a bunch of GUI related garbage that's not necessary).
<li>If you click the download link, it should just give you the file itself labelled <code>phantomjs</code>. There's no extension, but that's not needed anyway.</li>


<li>Drop that file into <code>/usr/bin</code> (easiest way, since that directory is in the <code>$PATH</code> variable for every user on a system).</li>


<li>Once there, it's best to assign ownership to root. You can do this with <code>sudo chown root:root /usr/bin/phantomjs</code></li>


<li>Next, make sure it has the right permissions with <code>sudo chmod 775 /usr/bin/phantomjs</code></ul></li>

Then it’s ready to go. Just make sure your .env file has PHANTOMJS_BIN_PATH=/usr/bin/phantomjs in it.

“…looking forward to dropping PhantomJS in v2…”

You just sold me on v2 with that one statement.

Hi @Titanfail, thanks so much for your input, after following the instructions i can confirm i am still recieving this error…

[2019-04-03 20:44:55] production.ERROR: PhantomJS - Invalid response http://192.168.0.253/view/ueakqjpw9rr7ipk2xqnr2vi8gfzvz2pe?phantomjs=true&phantomjs_secret=wm3x0cnl4elfzxkyz6ecgy8hhnbfsxcz: {“context”:“PHP”,“user_id”:1,“account_id”:1,“user_name”:“Nick Harding”,“method”:“GET”,“user_agent”:“Mozilla/5.0 (Windows NT 6.1; WOW64; rv:66.0) Gecko/20100101 Firefox/66.0”,“locale”:“en”,“ip”:“192.168.0.6”,“count”:1,“is_console”:“no”,“is_api”:“no”,“db_server”:“mysql”,“url”:“test_headless”} []

any ideas what the next steps are?

Cheers.

Other than PhantomJS no longer crashing, I’m unfortunately out of my depth on this one.

Possibly a dumb question, but did you have PHANTOMJS_SECRET set in your .env file? The one you pasted had other keys and such redacted, but it looked like that entry was completely blank.

Again, thanks for your reply. These are the 2 settings i have regarding phantom js…

PHANTOMJS_BIN_PATH=/usr/bin/phantomjs
PHANTOMJS_SECRET=wm3x0cnl4elfzxkyz6ecgy8hhnbfsxcz

If i run the test script i get this returned…

root@HHP-01:/var/www/invoiceninja# phantomjs test.pjs
\n{
“errorCode”: 408,
“errorString”: “Network timeout on resource.”,
“headers”: [
{
“name”: “Accept”,
“value”: “text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8”
},
{
“name”: “User-Agent”,
“value”: “Mozilla/5.0 (Unknown; Linux) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1”
}
],
“id”: 1,
“method”: “GET”,
“time”: “2019-04-05T18:21:31.589Z”,
“url”: “http://192.168.0.2/view/ueakqjpw9rr7ipk2xqnr2vi8gfzvz2pe?phantomjs=true&phantomjs_secret=wm3x0cnl4elfzxkyz6ecgy8hhnbfsxcz_”,
“status”: 408,
“console”: []
}root@HHP-01:/var/www/invoiceninja#

So it would appear PhantomJS is doing what it’s supposed to, and it’s the server itself having an issue. The only other thing I can think of is to check the KeepAliveTimeout setting in your Apache config (assuming you’re using Apache and not nginx, obviously).

Might be a long-shot, but take a look in /etc/apache2/apache.conf. Look at the entries for KeepAlive, MaxKeepAliveRequests, and KeepAliveTimeout. They’re probably fine, but couldn’t hurt to check them anyway.

this is the config, i did alter it to this and tried the same test script and its still the same :frowning:

Timeout: The number of seconds before receives and sends time out.

Timeout 300

KeepAlive: Whether or not to allow persistent connections (more than

one request per connection). Set to “Off” to deactivate.

KeepAlive On

MaxKeepAliveRequests: The maximum number of requests to allow

during a persistent connection. Set to 0 to allow an unlimited amount.

We recommend you leave this number high, for maximum performance.

MaxKeepAliveRequests 0

KeepAliveTimeout: Number of seconds to wait for the next request from the

same client on the same connection.

KeepAliveTimeout 100

Another dumb question, but did you restart Apache after making changes?

Regardless though, the settings you posted are the same ones I have (and those are default, I believe), so the problem is definitely elsewhere. Where, however, is unfortunately out of my wheelhouse. Wish I could be more help, but I’m just as stumped as you are at this point.

Yeah i restarted apache, its fully updated etc, this is killing me. im boarderline passing it off and finding another invoice platform. its a shame as there is not a lot of information on the web for this fault either :frowning:

I setup an Invoice Ninja install on my RPi trying to figure out what’s going on. The good news is that I’m able to replicate the issue. The bad news is I’m nowhere closer to figuring it out. I’ve tried removing the password requirement and eliminating the PhantomJS secret in .env, I’ve tried disabling IPv6, etc., and I’m still scratching my head.

Starting to wonder if it might be a strange issue with the ARM build in general, since I don’t have any trouble on my actual production server that runs on an x86_64 system.

Just for kicks (if you have the time and inclination), try setting up a VM on an Intel/AMD-powered system and installing IN on that.

Thanks for putting in the time and looking into the same issue im having. I do have a server with digital ocean (ubuntu) which i could install IN on but i wanted to run it on my Pi at home as the server in the cloud is for a seperate business, i guess i could run it on that server but wanted to keep them seperate and have my invoicing system for my Heating and plumbing company at home.

Have you managed to look into it any further? as i feel like im getting no where with it and defeated.

Cheers.

Meant to say set it up on an x86 VM just to see if the problem happens there as well. Trying to rule out all the issues.

Looked into it some, but as no sane person would ever call me a developer, I’m basically just poking it with a stick and seeing what happens.

Chased a wild thought and wondered if there was some difference between the zip file install and the composer install, so I started over and tried both. Same problem each time. And whether using the cloud or local phantomjs, I get back “Failed to load PDF document” when I hit the test button.

Additionally, just before that’s going on, I see production.ERROR: TypeError: Attempting to change value of a readonly property. several times in laravel-error.log (tested with a blank log file, so this error is definitely related).

There seems to be a similar thread from last year, but unlike that thread, I have no issues viewing or downloading the PDF file. It’s only when phantomjs is involved that the problem happens.

Basically just posting to hopefully give the @hillel and the crew more information to go on. I’m at the end of my abilities, especially since I have zero issues on my production install.