In this article I'd like to share some tips on creating and running various script based projects (i.e. projects in which you run something in command line). No Grunt or any other additional helper application is required. You just need Netbeans.
Also added a bonus on setting up PHP debugging (XDebug) on Windows.
The main trick with Netbeans is that project type "PHP" can be configured to run any command. This is true not only for Node.js but any other web technologies project.
So here is a quick step-by-step to create a Node.js project:
Run configuration
.Run as
choose Script (...)
.Use Default PHP Interpreter
.PHP Interpreter
choose node
binary.Index file
is the JavaScript file you want to run. Can be relative to repository root.Working Directory
must be a full path. Set it to whatever you need.Note that Netbeans allows to add more one Run configurations so you can easily switch between running various command or with different parameters.
Also note that there is a dedicated NodeJS plugin for Netbeans, but apart for adding a NodeJS icon to the project, it doesn't do anything useful... Or at least not the last time I checked (which was somewhere in January).
If you are running PHP from command line it can be significantly slow to start. It may take more time to start PHP than actual script execution time. So how to fix this?
The answer is easy - use -n
PHP option. This will ignore php.ini altogether and so will not load any extra modules. And in consequence PHP will run much faster. The option is universal, but is particularly useful when you are using Netbeans to build your application with PHP script.
To add this PHP option in Netbeans do the following:
Run configuration
.Configuration
you want to change.PHP Options
field add -n
. The command to run your script should become something like: php -n your.script.php
.Alternative, and maybe even better solution, is to use separate ini for Apache HTTPD server and separate for PHP command line. The easiest way to do that is to copy your current php.ini to a separate folder (e.g. apache-ini
) and point Apache to this ini. This is done by changing PHPIniDir
directive in httpd.conf
. Example:
PHPIniDir "C:/programs/PHP/apache-ini/"
After that you can remove PHP extension
statements from main php.ini
. In particular php_curl.dll
seems to load very slowly.
Note that this way PHP unit tests will also run MUCH faster and you will be able to debug your scripts and command line debugging will also be much faster.
By default debugging is not possible. Thankfully installing XDebug is quite easy if you follow this steps:
[XDEBUG] zend_extension="c:/programs/PHP/ext/php_xdebug-2.1.2-5.3-vc6.dll" xdebug.remote_enable=true xdebug.remote_host=localhost xdebug.remote_port=9000 xdebug.remote_handler=dbgp
Of course the path will be different depending on the DLL you downloaded and where you put it.