PHPStorm cache on virtual RAM disk [MacOS]

When using a SSD disk, and enough RAM on the system, I always prefer to move software cache files into a virtual RAM disk, in order to extend the disk life, and also gain more speed.

The command on MacOs to create a 512Mb Virtual volume (under /Volumes/RAMDisk) is

diskutil erasevolume HFS+ 'RAMDisk' `hdiutil attach -nomount ram://524288`;

After that, you can create your symlink, and move that command in a startup script

PHPStorm script

Here is the script I’m using to create the virtual Disk and the index and cache directories for PHPStorm. Of course you need to symlink them the first time you use them (see the comments in the gist).

You’ll lose the cache and index next time you restart your computer or unmount your RAMDisk, but that’s something I actually prefer, to keep the cache clean from old projects and libraries.

How to fix docker slowness (volumee mounting) with Docker-sync + PHPStorm file watchers

I’ve experienced lots of slowness using docker for Mac (xhyve), due to volume mounting.

A solution to that I’ve been using successfully for a few week is composed by docker-sync (rsync) and PHPStorm file watcher.

docker-sync (rsync)

I’ve used the rsync solution for docker-sync. Simple, but the downside is that newly created files in the container are not shared outside. That’s not generally a problem except when some code is generated from inside the container (e.g. Doctrine migrations). When needed, a normal mounting for those directories can still be used, or (more complicated), the file can be copied into the host with a docker cp command.

Other downsides are the slowness to rsync watch (a few seconds that can be annoying in some cases), that leads me to the next point:

PHPStorm file watcher

PHPStorm supports the execution of custom scripts on save (file watchers). The idea is having those file watchers to perform an immediate docker cp inside the container with the modified file.

The screenshot should be clear enough. Replace docker bin with the real path of your docker executable (not the symlink), and <CONTAINER_NAME> with your docker container, and adjust /app/ to have docker cp copying files where your docker container expects.

Depending on your needs, you might want to adjust your shares, and decide whether vendor directory needs to be watched or not.

Note: You can’t just use the file watcher, or you’ll have the rebuild (or manually copy all the files) any time you switch branch.

PHPStorm File Watcher Docker cp

PHPStorm File Watcher to copy files inside docker container – example


How to create DEB packages for ubuntu/debian

linuxTo create a DEB package, you just need to create a directory with the files, respecting the same structure starting from “/”, plus a couple of files with the configuration.

The command dpkg –build will then create the DEB files that you can install with dpkg -i mysqldb2html.deb.

For detailed, instructions, read this article on

For an example of application of mine, just packaging a single script, click here

97 things every programmer should know: personal notes

Last month I saw a book flying about the office, containing useful tips from developers. 97 suggestions from experienced developers. Amazon is still selling it, so I suggest you read it if work as a software developer or you occasionally dip into coding: 97 Things Every Programmer Should Know: Collective Wisdom from the Experts

I’ve finished reading it, and I took some notes while reading. Some concepts and suggestions were obvious, as I hear them many times from the community (blogs, conferences, colleagues) or I’ve already personally experienced them. I’ll paste those my notes here, with the hope that you can find something valuable from looking through them.

Continue reading

Linux bash: pipe output to an email address as attachment

on ubuntu 11.10

sudo apt-get install mailutils
sudo apt-get install sharutils
Install mailutils as a local server, it will send the mail as <whoami>@<hostname>

To send the manual of mysqldump to my kindle (amazon will convert and deliver for me, of cours add the sender to the allowed addresses here )

man mysqldump | uuencode attach.txt | mail -s “

Xdebug debug with Netbeans on Linux

XDebug is a free PHP extension to debug variables of your applications. Combined with Netbeans for PHP debug features (break points, variable watching and flow execution navigation, see screenshot on the left), it allows to have a complete debug environment.

What it’s really interesting is the possibility to place breakpoints in any file, even though not called directly in the local URL. That is required when working with web applications with URL routing/rewriting sudh as MVC applications (Zend Framework, Symfony etc..)  where the PHP code in a controller action does not match with its path in the local URL.

Here are the easy steps to follow in order to configure Xdebug for Linux Ubuntu 10.04 LTS. I’ll write the full commands to make it easier by copy & paste.

-) download the xdebug extension

sudo apt-get install php5-xdebug

-) check where the extension is installed

sudo find /usr/lib/php5 | grep xdebug

-) open the php.ini file (inside apache)

sudo vim /etc/php5/apache2/php.ini

and add these lines at the end of the file (replace with the right module path)


note1: could be elsewhere. use find /usr/lib -name to find the correct path
note2: see other xdebug settings

-) restart apache

sudo /etc/init.d/apache2 restart

-) Netbeans: tools->options->PHP
Tick ”Watches and Baloon Evaluation” (*), Untick “Stop at first Line” (not really useful except when debugging the application bootstrap).

(*): Xdebug is unstable with this options, however I found it very useful and enough stable for my purposes. It’s possible that Netbeans crashes with the current version, restart it in case.

5) Netbeans: right click on the project ->properties->Run configuration -> run as local website. Insert the (virtualhost) local URL. Do not insert any index file if the application uses URL routing, or Netbeans will launch the relative script path in the URL.

6) Netbeans: place your breakpoints by clicking on the line number, then start the debug (Under Debug->debug or Ctrl+F5). Netbeans will open the browser at the local URL, and when reaching the breakpoitns, netbeans will show a red icon on the line.
Depending on the browser, the focus will return to Netbeans (go manually if it does not).
Select the code / expression to watch/evaluate. Netbeans will show a baloon tip with the value. Alternatively, right click and select “new watch” to have the expression and the values appearing in the debug panel.
Use F5 to go to the next breakpoint, F7/F8 to step into/over.

As mentioned, Xdebug is unstable with the option set in the step 4. If watching some expressions crashes netbeans, use the “new watch” option instead.

How to recursively check syntax of PHP files

The executable of PHP supports the ‘-l’ option, that checks the syntax instead of parsing the file.
Using the command ‘find’, it’s possibile to do a interesting operation: syntax checking of all the files recursively, to avoid parse errors in some script !!

find ./ -type f -name *.php -exec php -l {} ;

the result will be a list of files, example:

No syntax errors detected in ./codebase/controller/
No syntax errors detected in ./codebase/controller/
Errors parsing ./codebase/controller/site/
No syntax errors detected in ./codebase/controller/

We can improve the script and print only the file with suntax errors using ‘grep’

find ./ -type f -name *.php -exec php -l {} ; | grep “Errors parsing “;

To launch it from a PHP script

passthru(‘find ./ -type f -name *.php -exec php -l {} ; | grep “Errors parsing ” ‘);

Updated: To skip .svn directories add the option :
-not -regex ‘.*/.svn/*.*’

Monitor linux web-servers with monit

monit is a utility for managing and monitoring processes, files, directories and devices on a Unix system. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations. E.g. monit can start a process if it does not run, restart a process if it does not respond and stop a process if it uses to much resources. You may use monit to monitor files, directories and devices for changes, such as timestamps changes, checksum changes or size changes.

Monit is controlled via an easy to configure control file based on a free-format, token-oriented syntax. Monit logs to syslog or to its own log file and notifies you about error conditions via customizable alert messages. Monit can perform various TCP/IP network checks, protocol checks and can utilize SSL for such checks. Monit provides a http(s) interface and you may use a browser to access the monit program.”[ref] .

How to install in ubuntu 8.10

  • sudo apt-get install monit
  • edit /etc/monit/monitrc and remove comments
    #launch system mon every 2min
    set daemon 120
    #set web interface on port 2812
    set httpd port 2812 and
    # allow localhost and request from IP
    allow localhost
    #request username (admin) and password(monit)
    allow admin:monit
    #check apache
    check process apache with pidfile /usr/local/apache/logs/
    #check mysql service (other server)
    check host myserver with address
    if failed icmp type echo count 3 with timeout 3 seconds then alert
    if failed port 3306 protocol mysql with timeout 15 seconds then alert
    #set alerts via email
    set mailserver
    set alert
  • check the syntax of the previous file with
    sudo monit -t
  • edit /etc/default/monit
  • start deamon !!
    sudo /etc/init.d/monit start
  • call web interface
    use admin and password specified before