sindresorhus/grunt-php — pull request #15 by amercier (2013-12-07 20:36:55+00:00)
Title: Added 'done' var to prevent this.async()() to be called twice when keepalive is true

With a simple Gruntfile like this:

```js
grunt.initConfig({
php: {
options: {
port: 8000,
// hostname: '0.0.0.0'
hostname: '127.0.0.1'
},
server: {
options: {
base: '.',
}
},
}
});
```

I have the following result when running grunt:server:keepalive:

```bash
Yunnan:grunt-php-test amercier$ grunt php:server:keepalive
Running "php:server:keepalive" (php) task
PHP 5.4.17 Development Server started at Sat Dec 7 21:06:58 2013
Listening on http://127.0.0.1:8000
Document root is /Users/amercier/Development/grunt-php-test
Press Ctrl-C to quit.
[Sat Dec 7 21:06:58 2013] 127.0.0.1:64790 [200]: /
[Sat Dec 7 21:06:58 2013] 127.0.0.1:64791 [200]: /
[Sat Dec 7 21:06:58 2013] 127.0.0.1:64792 [200]: /
[Sat Dec 7 21:06:58 2013] 127.0.0.1:64793 [200]: /
[Sat Dec 7 21:06:58 2013] 127.0.0.1:64795 [200]: /
[Sat Dec 7 21:06:58 2013] 127.0.0.1:64796 [200]: /
[Sat Dec 7 21:06:58 2013] 127.0.0.1:64797 [200]: /
[Sat Dec 7 21:06:58 2013] 127.0.0.1:64798 [200]: /
[Sat Dec 7 21:06:58 2013] 127.0.0.1:64799 [200]: /
[Sat Dec 7 21:06:58 2013] 127.0.0.1:64800 [200]: /
[Sat Dec 7 21:06:58 2013] 127.0.0.1:64801 [200]: /
[Sat Dec 7 21:06:58 2013] 127.0.0.1:64802 [200]: /
[Sat Dec 7 21:06:58 2013] 127.0.0.1:64803 [200]: /
[Sat Dec 7 21:06:58 2013] 127.0.0.1:64804 [200]: /
[Sat Dec 7 21:06:58 2013] 127.0.0.1:64805 [200]: /
[Sat Dec 7 21:06:58 2013] 127.0.0.1:64806 [200]: /
[Sat Dec 7 21:06:58 2013] 127.0.0.1:64807 [200]: /
[Sat Dec 7 21:06:58 2013] 127.0.0.1:64808 [200]: /
[Sat Dec 7 21:06:59 2013] 127.0.0.1:64809 [200]: /

```

As you can see, requests are still being sent (to check if the server is alive), even if we receive a 200 OK from the PHP server.

After a little debugging I found that calling `cb()` at [tasks/php.js#L63](https://github.com/sindresorhus/grunt-php/blob/master/tasks/php.js#L63) triggers the http error event callback at [tasks/php.js#L21](https://github.com/sindresorhus/grunt-php/blob/master/tasks/php.js#L21).

I haven't dug further, but this could be due to `this.async` trying to *do something* while we still are in the http request callback method at [tasks/php.js#L17](https://github.com/sindresorhus/grunt-php/blob/master/tasks/php.js#L17).

Well, my solution is not perfect. I would rather prefer to find out what is really occurring. Any ideas?