Reputation: 3324
When I use grunt-contrib-connect in the Gruntfile.js for my HTML files, and the task is called, the browser launches and connects with LiveReload without issue.
I am now trying to do the same with PHP files so I am using grunt-php. The author states that grunt-php is "pretty much a drop-in replacement for grunt-contrib-connect".
I have copied the options for grunt-contrib-connect to the grunt-php task, and added keepalive
and open
, but the browser does not get launched and no connection is made. The terminal however shows:
Running "php:livereload" (php) task
PHP 5.4.17 Development Server started at Mon Nov 11 15:56:04 2013
Listening on http://localhost:9000
Document root is /Users/fisu/Sites/generator-site-playground/dev
My task looks like:
php: {
options: {
keepalive: true,
open: true,
port: 9000,
livereload: 35729,
hostname: 'localhost',
base: 'dev'
},
livereload: {
options: {
open: 'http://localhost:9000',
base: 'dev'
}
}
}
I have tried different hostnames, but still the browser will not launch and connect. Am I missing an option?
Upvotes: 1
Views: 904
Reputation: 10146
It's not just you. The problem seems to be with this method: https://github.com/sindresorhus/grunt-php/blob/master/tasks/php.js#L51-L59 - open() never seems to get called because it's waiting for a HTTP 200 which it won't get unless a browser hits the server and requests something. At least that seems to be the case on my machine, I don't know how well tested that method is or anything. A temporary fix could be to move that call out of that method; go into the node_modules/grunt-php/tasks/
directory and edit the file like so:
(l49) // check when the server is ready. tried doing it by listening
// to the child process `data` event, but it's not triggered...
checkServer('http://' + host, function () {
if (!this.flags.keepalive && !options.keepalive) {
cb();
}
}.bind(this));
// open the browser straight away
if (options.open) {
open('http://' + host);
}
I've also filed an issue. https://github.com/sindresorhus/grunt-php/issues/14
Upvotes: 2