Skip to content

Commit

Permalink
Use the php-server package
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed May 14, 2019
1 parent cfc25ce commit 40827e3
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 239 deletions.
37 changes: 11 additions & 26 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,72 +10,62 @@ module.exports = grunt => {
},
watch: {
test: {
files: ['noop']
files: [
'noop'
]
}
},
php: {
open: {
options: {
port: 7007,
base: 'test',
keepalive: true,
keepAlive: true,
open: true
}
},
openUrl: {
options: {
port: 7008,
base: 'test',
keepalive: true,
keepAlive: true,
open: '200/index2.php'
}
},
test200: {
options: {
port: 8008,
hostname: '0.0.0.0',
base: 'test/200',
binary: 'php'
base: 'test/200'
}
},
test301: {
options: {
port: 8009,
hostname: '0.0.0.0',
base: 'test/301',
binary: 'php'
base: 'test/301'
}
},
test400: {
options: {
port: 8010,
hostname: '0.0.0.0',
base: 'test/400',
binary: 'php'
base: 'test/400'
}
},
test404: {
options: {
port: 8011,
hostname: '0.0.0.0',
base: 'test/404',
binary: 'php'
base: 'test/404'
}
},
test500: {
options: {
port: 8020,
hostname: '0.0.0.0',
base: 'test/500',
binary: 'php'
base: 'test/500'
}
},
testEnv: {
options: {
port: 8021,
hostname: '0.0.0.0',
base: 'test/env',
binary: 'php',
env: {
FOOBAR: 'foobar'
}
Expand All @@ -84,21 +74,16 @@ module.exports = grunt => {
testDirectives: {
options: {
port: 8022,
hostname: '0.0.0.0',
base: 'test/directives',
binary: 'php',
directives: {
'error_log': 'foobar'
}
}
},
serve: {
options: {
hostname: '127.0.0.1',
port: 9000,
base: 'test/browsersync',
keepalive: false,
open: false
base: 'test/browsersync'
}
}
},
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grunt-php",
"version": "2.0.0",
"description": "Start a PHP-server",
"description": "Start a PHP server",
"license": "MIT",
"repository": "sindresorhus/grunt-php",
"author": {
Expand All @@ -27,9 +27,7 @@
"http"
],
"dependencies": {
"bin-version-check": "^4.0.0",
"get-port": "^5.0.0",
"open": "^6.3.0"
"php-server": "^0.2.0"
},
"devDependencies": {
"got": "^9.6.0",
Expand Down
108 changes: 16 additions & 92 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# grunt-php [![Build Status](https://travis-ci.org/sindresorhus/grunt-php.svg?branch=master)](https://travis-ci.org/sindresorhus/grunt-php)

> Start a [PHP-server](http://php.net/manual/en/features.commandline.webserver.php)
> Start a [PHP server](https://php.net/manual/en/features.commandline.webserver.php)
Pretty much a drop-in replacement for [grunt-contrib-connect](https://github.com/gruntjs/grunt-contrib-connect). Useful for eg. developing PHP projects or running tests on it.
Useful for developing PHP projects or running tests on them.

Uses the built-in server in PHP 5.4.0+.
Pretty much a drop-in replacement for [grunt-contrib-connect](https://github.com/gruntjs/grunt-contrib-connect), except for the `middleware` option.

*Doesn't have a `middleware` option as grunt-contrib-connect does.*
Uses the PHP built-in server.


## Install
Expand Down Expand Up @@ -37,14 +37,14 @@ grunt.registerTask('default', ['php']);

## Examples

#### Start a persistent PHP-server and open in browser
#### Start a persistent PHP server and open in browser

```js
grunt.initConfig({
php: {
test: {
options: {
keepalive: true,
keepAlive: true,
open: true
}
}
Expand All @@ -61,11 +61,8 @@ grunt.initConfig({
php: {
dist: {
options: {
hostname: '127.0.0.1',
port: 9000,
base: 'dist', // Project root
keepalive: false,
open: false
base: 'dist' // Project root
}
}
},
Expand Down Expand Up @@ -118,12 +115,14 @@ grunt.registerTask('phpwatch', ['php:watch', 'watch']);
#### Add path for a custom error log

```js
const path = require('path');

grunt.initConfig({
php: {
dist: {
options: {
directives: {
'error_log': require('path').resolve('logs/error.log')
'error_log': path.resolve('logs/error.log')
}
}
}
Expand All @@ -135,103 +134,28 @@ grunt.registerTask('default', ['php']);

## Options

### port

Type: `number`<br>
Default: `8000`

The port on which you want to access the webserver. Task will fail if the port is already in use. Use the special value `?` to use a system-assigned port.

### hostname

Type: `string`<br>
Default: `'127.0.0.1'` *(Usually the same as `localhost`)*

The hostname the webserver will use.

Use `0.0.0.0` if you want it to be accessible from the outside.

### base
Supports all the [`php-server` options](https://github.com/sindresorhus/php-server#options) in addition to the ones below.

Type: `string`<br>
Default: `'.'`

From which folder the webserver will be served. Defaults to the directory of the Gruntfile.

### keepalive
### keepAlive

Type: `boolean`<br>
Default: `false`

Keep the server alive indefinitely. Any task specified after this will not run.

This option can also be enabled ad-hoc by running the task like `grunt php:targetname:keepalive`

### open

Type: `boolean | string`<br>
Default: `false`

Open a browser when task is triggered.

Can be one of the following:

- `true`: opens the default server URL ('http://' + hostname + port)
- a relative URL (string): opens that URL in the browser. Useful when testing pages that are not the default one.

### router

Type: `string`

Optionally specify the path to a [router script](http://php.net/manual/en/features.commandline.webserver.php#example-380) that is run at the start of each HTTP request. If this script returns `false`, then the requested resource is returned as-is. Otherwise the script's output is returned to the browser.

Example router script:

```php
<?php
// router.php
if (preg_match('/\.(?:png|jpg|jpeg|gif)$/', $_SERVER["REQUEST_URI"])) {
return false; // serve the requested resource as-is
} else {
echo "<p>Thanks for using grunt-php :)</p>";
}
?>
```

### binary

Type: `string`<br>
Default: `'php'`

Path to the PHP binary. Useful if you have multiple versions of PHP installed.

### ini

Type: `string`<br>
Default: Built-in `php.ini`

Path to a custom [`php.ini`](http://php.net/manual/en/ini.php) config file.
This option can also be enabled ad-hoc by running the task like `grunt php:targetname:keepAlive`.

### silent

Type: `boolean`<br>
Default: `false`

Suppress output produced by the PHP-server.

### directives

Type: `object`<br>
Default: `{}`

Add custom [ini directives](http://php.net/manual/en/ini.list.php).
Suppress output produced by the PHP server.

### env

Type: `object`<br>
Default: `{}`
## Related

Set environment variables for the PHP process.
- [php-server](https://github.com/sindresorhus/php-server) - Start a PHP server from Node.js


## License
Expand Down
Loading

0 comments on commit 40827e3

Please sign in to comment.