AuthorCam Spiers

PHP Library Creator

There are numerous tedious tasks to perform in order to get a modern PHP library built. The bulk of the work is of course spent on developing the library’s functionality, but often a barrier to separating code out into separate libraries is the initial step of creating the library and getting it integrated with existing code.

PHP Library Creator attempts to make the prep work on new libraries less time consuming. For installation instructions check it out on github. If you want to see a preview of it in action watch the video below.

SilverStripe Twig

As a long time developer of SilverStripe applications and websites, I have often found myself fighting against SilverStripe’s template engine. Its syntax is beautiful but its implementation poor.

SilverStripe Twig enables the use of Twig in SilverStripe. For those who haven’t used Twig before, Twig is an excellent template engine created by the founder of symfony Fabien Potencier and many collaborators. Twig is well tested, actively supported, feature rich template engine with an extension system.

Check it out on github for installation instructions and a user guide.

PHP 5.3 JSON Pretty

For those who work often with JSON in PHP, PHP 5.4 came out with some nice new options for the json_encode function. In particular JSON_PRETTY_PRINT which outputs JSON in a more human readable format.

Unfortunately for those of us stuck with PHP 5.3 for whatever reason, we don’t have this option available.

In comes this simple JSON Pretty service to the rescue:

$jsonPretty = new Camspiers\JsonPretty\JsonPretty;

echo $jsonPretty->prettify(array(‘test’ => ‘test’));

JSON pretty can have an array as input or a JSON string, and the result with be pretty human readable JSON.

You can find the source and installation instructions on github.

Installing Sphinx 0.9.9 from MacPorts

Sphinx 0.9.9 is now available through MacPorts. If you want MacPorts but haven’t got it head on over here.

Install Sphinx

For a new install use the following commands:

sudo port -d selfupdate #this updates the PortFile tree and index
sudo port install sphinx

If you have an older version this should upgrade to 0.9.9

sudo port -d selfupdate  #this updates the PortFile tree and index
sudo port upgrade outdated  #upgrades

Check install

If you don’t remember choosing a different directory on install then you will find MacPorts related stuff (including Sphinx) in /opt/local/

Ensure /opt/local/bin is in $PATH

echo "${PATH//:/$'\n'}"  #display all dirs on path on a separate line

To check the installation here are some commands:

which searchd
which indexer
searchd -h

Setting up config

If this is a fresh install you may need to copy the distribution config from sphinx.conf.dist to sphinx.conf. There is also a file without comments called sphinx-min.conf.dist

cd /opt/local/etc/sphinx/

if [ ! -f sphinx.conf ]
then
sudo cp sphinx.conf.dist sphinx.conf
fi

sudo open sphinx.conf #open the config

port gohome sphinx #opens sphinx homepage

Docs and php API

If you are working with php there is a api file here sphinxapi.php with some docs here

For help setting up indexes here are the Sphinx docs http://sphinxsearch.com/docs/current.html

Some helpful commands for when you are playing around with your sources and indexes.

#watch as connections come in
sudo searchd --console
#this will reindex all and send a signal to the running searchd process to rotate updated indexes automatically
sudo indexer --all --rotate

© 2014 Spirton

Theme by Anders NorenUp ↑