Dropbox, a swiss-knife tool for developers

dropbox Among the tools I consider useful, Dropbox is one ! It offers a free online storage space of 2 Gb with automatic synchronization with local directory and versioning ! I personally use to keep my digital books, guides, code snippets, software (php, apache, mysql, portable graphic software, IDEs, etc…) between two houses and workplace.

Nice features are the possibility to share contents with other dropbox users and get public links of the selected files (to let anyone to download that file). The second feature can be used to easily download our compressed files (custom libraries, frameworks) into our new hosting (wget via ssh).

Another feature I like is the “immediate upload“: if the same file (thanks probably to a hash of the file) is already on the dropbox servers (as uploaded by another dropbox user I suppose), the file is automatically copied online-to-online without the need to upload it.  Practically, any file downloaded online is probably already on dropbox, of course except personal files and compressed files. When saving the OpenOffice installer, it will be helpful.

Download and enjoy it ! (that’s an affiliate link, if you download from that link, I get  additional 250Mb of space, thanks 🙂 )

Free web-based software for project management

project managementAfter being part of a new team that works with outsourcing team with dynamic allocation of resources (developers) without using a software to plan and schedule the project, I’m now interested in experimenting some free web-based software for project management [project magement wiki].

As expected, the awesome wikipedia contains a page about the software used for project management, as well as a comparison of the  project management software.

Among the open source, web-based, here is the list of the ones that seem more insteresting, with some notes. I’m making this list in order to having them read to try.

See in this article how to manage developers

The power of the Regular expression on the web

Regular Expression are Swiss-knife tools developers should know, extremely useful for  web-purposes and unavoidable when dealing with content scraping.
A single call of a preg_match_all with a medium complex regular expression could save hundres of LOC and time as well as obtaining much more maintainable code.

There  are advanced features like subpatterns and conditional expressions. They might be useful to extract some patterns, task  otherwise not easily feasible.

Pattern Syntax guide – php.net

Useful links about regular expressions

Zend tool not working after Netbeans 6.9 setup

Netbeans 6.9 modifies the  zend framework tool and adds an additional class in order to use it directly from the IDE.

The problem is that Netbeans changes the common INI file of the tool (.zf.ini placed inside the user folder). Without specifying additional parameters, the tool does not work anymore from the external command line.

My quick solution was temporarily moving the INI file, however it’s possible to specify additional parameters to use another config file.

the command

zf create project ...

returned the error

prompt>zf create project
Warning: include_once(NetBeansCommandsProvider.php): failed to open stream: 
No such file or directory in C:wampwwwZendFramework-1.10.6libraryZendLoader.php on line 146
PHP Warning:  include_once(): Failed opening 'NetBeansCommandsProvider.php' for inclusion )
 in :wampwwwZendFramework-1.10.6libraryZendLoader.php on line 146

Checking PHP script performance with Xdebug

Xdebug [http://www.xdebug.org/] is a useful tool to debug PHP scripts. An interesting feature is the script profiling.

If the option is enabled, Xdebug will be able to trace and save information (time, details) about all the functions/methods called in the script (CLI or Apache).

The aim of the profiling is mainly recognizing bottlenecks or simply what parts of the code that are slow.

In order to analyze the log file created, use KCacheGrind or WinCacheGrind (see screenshots below).

Setup and docs at [http://www.xdebug.org/docs/profiler].

Configuration for Wamp (PHP 5.3)

xdebug.profiler_enable = 1


cache grid php profiling

Functional testing for web applications: Selenium IDE for firefox

In a previous post I wrote about PHP Unit testing.

In software science, the levels above Unit testing are Integration, System and System integration testing.

For a standard web application I suggest to use only Selenium [official site], a powerful complete framework , distributed with apache licence 2.0 (a free-software, GPL compatible).
Selenium includes many components. In my opinion the most useful is Selenium IDE [page], a firefox plugin to create action tests, play and check results.

It’s very easy to use the IDE [official manual], but to write good tests it needs some practice.
Basically, a test case is a sequence of commands, and a test suite is a cluster of test cases.
To create actions the tool allows to record user actions (clicks, page opening…) or manually insert/edit (mainly to insert verify-actions) and play the test case (or test suite), then check results.
It’s possible to export the test cases in many formats (html table, o export (html table format, PHPunit selenium extension, etc…) and to import (only html table).

Every command has only one or two arguments. The command reference is present in selenium IDE. Here are the commands I mainly use and I suggest:
  • open dir/page.html
    open the url specified
  • type id=phone 123456
    fill in field with id=phone with the text “123456”
  • clickAndWait id=elementID
    click on the link with ID equal to “elementID” .
  • clickAndWait link=text
    click on the link with “text” as internal text (a “text-dependent” approach is plainly not recommended)
  • verifyTextPresent done
    Verify the page contains the text “done”. If not, the test will fail at runtime. (be careful: “text-dependent”).
  • verifyElementPresent id=elementID
    Verify the page contains the element with ID equal to “elementID”. If not, the test will fail at runtime.
  • assertConfirmation
    assert a javascript confirmation appear
Instead of use the ID to locate an element (example: “id=linkA”) it’s possibile to use XPath expressions [syntax by w3c school] as locators. Example: “//div//a[2]” is the second link inside the “div” tag. I don’t suggest to use XPath: if you (or the designer) change the template (position, or text inside links, or change teh text) the test will not work !
To write solid reliable tests, remember to use a univocal ID for elements to test (message confirmation, links, form fields..), and write the test as soon as the application is working (you will easily and quickly test the correct application behaviour after adding new features).

To test CRUD forms, I suggest to write the html code (template) using a different ID for confirmation messages and error messages
[?php if ($result ): ?]
[div id=”postok”]submit ok[/div]
[?php else: ?]
[div id=”posterr”][?php echo $messageError ?][/div]
[?php endif; ?]
To test the result of this form:
verifyElementPresent postok
verifyTextNotPresent posterr

Selenium IDE screenshot

SVN to FTP/web on Windows with svn client+winscp

How to deploy a web application and to quickly deploy future updates/patches from a SVN repository into a remote web server (only with ftp access and without possibility to setup svn client) ?
Here are my suggested steps:

  1. export SVN (that is obtain the last repository without “.svn” directories)
  2. process the exported SVN (e.g. adding or deleting files before uploading)
  3. upload (1st time) or synchronize (update new files to the remote webserver)
  4. chmod folders (only 1st time or new folders)
All the 4 steps are executable from a handy shell script using:
  • Linux: svn client (1) + rsync (3)
  • Windows: svn client subversion (1) + winscp script (2)
Example of a svn to ftp batch in Windows (with subversion client and winscp, both are free):
  1. Create a profile with winscp, and set local folder “c:tempsite1” and remote folder (e.g. “/httpdocs” ).
  2. Write a batch file svn2ftpsite1.bat
    set PATHFOLDER=c:tempsite1
    svn export svn:// %PATHFOLDER% –force
    del %PATHFOLDER%file-not-to-upload* /q
    copy c:other-folderfile-to-add-to-site1 %PATHFOLDER%
    c:path-towinscp.exe /console “open winscp-profile” “synchronize remote” “chmod 777 uploads” “close”
  3. Save. And launch when you want to update the remote site (don’t forget to commit the svn before)
Read the winscp online scripting manual for further information.
Note: if the web server (Linux I think!) can access the SVN repository, has SSH server and subversion client, you can export directly the repository in the web server.
Note: if the web application works correctly, take note of the current repository version. in case of future problems you will be able to export that revision (svn client command line option) and restore the online web site.
Note: If you can install svn client in the web server and the repository is visible from the web server, you can use “check out” and “update” directly in the webserver, then use an apache rule to hide .svn directories
RewriteRule /.svn /errorpage

Debugging techniques with free tools [updated 30 June]

  • Netbeans PHP 6.* + Xdebug + Firefox (with netbeans extension to server debug with javascript) !
    howto configure with
    Wamp 2.0h:
    – download
    php_xdebug-2.0.4-5.2.8.dll into the Wamp folder
    – open port 9000 in the firewall
    – edit php.ini adding


    – now, let’s debug the script with Netbeans choosing “Server side PHP with client side Javascript”. Netbeans will install an extension for firefox which will allows to launch the script in the server (localhost). The extension will “pause” (thanks to extension and javascript) the server execution and it will be possibile to debug with netbeans when the breakpoints (put them in valid lines) will be reached.

    See the screenshot: array debug

    Note: obviously it’s possible to debug the script directly in the php command line (no browsers is needed).

    Tested with Netbeans 6.7, Wamp 2.0h

    see official wiki

  • Eclipse PDT + Xdebug ! both are free. In Eclipse you can set breakpoints, then run the application; when breakpoints are reached, Eclipse will show variable values (tree explorer for multi-level arrays )
  • debug with php code
    function debugAll(var_dump($GLOBALS));
    “[pre]; debugAll(); print [/pre];
  • zend debugger […]
  • […]