Help me test Tentacles Installation!

I want to make Tentacle a dream to install.

For the time being I would like to get a group of potential users to test the setup process.

The ideal tester should be a little techie, you don’t need to be a hard core nerd but you should understand what the errors mean.

Download it!

And please send me feedback on the blog, or send a tweet, even an email.

Thanks!

DIY simple staging server.

While working on Tentacle I needed a simple solution for testing code on a remote web server.

In the past I would work locally and syncing with FTP to the server and then tested off of the remote server, I used SVN for my source control. Within the last year I have started working locally and using Git as my main source control.

This left a bit of a gap in my process where I could no longer test on a remote server without updating it manually by S/FTP or opening terminal and manually calling a git pull.

Open terminal and manually git pull it did break up the work flow a bit so using the Dingo framework I created a very simple Git helper and gave it its own URL something like git/pull.

I then used a Github Post-Receive URL Hook found under admin/service hooks that pointed to my staging server git pull URL, every time I do a push to Github, Github will then automatically fire the URL thus triggering the pull helper.

One little note is that if you check out a dev branch on a staging server and also have a live server you would add a second URL with the same code on that liver server. One push would update both sites.

Just make sure the live server is on the right branch.

If you don’t feel like using a hook then no problem at all. Just call the URL in the browser and you will see the Git pull message.

Download View on Github

Dingo a Lightweight MVC PHP Framework

I have been using a small PHP MVC Framework called Dingo Framework.

Dingo is a Rapid Development Application Framework written in PHP by Evan Byrme. Dingo allows you to create dynamic changing websites easily and quickly.

Dingo is a relatively new full featured framework at a compact size of 70KB, It supports Fancy URL’s, Access Control List, User Authentication, ORM, and simple no SQL database interaction.

Dingo is very easy to leverage, adding 3rd parties libraries is dead easy. The configuration is simple with support for multiple database connections, auto load libraries and helpers.

Dingo is well documented, but a little out dated, You are probably better off checking GitHub for more up to date code.

Try the Dingo TextMate Bundle!

Download DIngo    Download the Bundle

PHP’s Memory Usage

This is a handy little Snippet that goes well with PHP Microtime. Not only are we concerned with our scripts execution time but we also want to make sure we are not using an exorbitant amount of memory in the process.

At the top of your script lets place the code that will start PHP’s Micro time.

$time_start = microtime(true);

At the bottom of your page, just before the “” tag we will put the Code that will calculate the execution time as well as how much memory was used to execute the script.

// RENDER TIME
$time_end = microtime(true);
$time = $time_end - $time_start;

echo "Loaded in \n";
echo round($time, 3)." Seconds <br />";
echo 'Peak: ' . number_format(memory_get_peak_usage(), 0, '.', ',') . " bytes\n <br />";
echo 'End: ' . number_format(memory_get_usage(), 0, '.', ',') . " bytes\n";

number_format() simply formats the number out put to look something like this “111,964″ instead of “111964″.

memory_get_peak_usage() is going to return a value based on the peak memory used during the execution. This is more so were we want to see improvements made.

memory_get_usage() will return the amount of memory used once the script is done processing, basically the amount currently used once the crunching is finished.

It’s a good idea to think about memory usage when you are making web applications as this can impact your hosting.

Say you have a VPS server with 256mb of ram but the foot print of each user is 25mb you can can only have about 10 people accessing your site before you running server errors exceeding memory limits. Any work involving processing of images a lot of data manipulation can eat up memory in a hurry.

Running PHP5 in the Dreamhost CLI

Some times a PHP framework might include a command line interface, Cake PHP or Symfony for example have a tool that will generate some code based on your database.

Symfony unlike Cake PHP will only work with PHP 5, When I tested the version of php on the front end I got 5.2.4 and figured I’m good to go.

While after running the Symfony command line tool to build my project I got a php error.

This is due to the setup of most shared web hosting environments PHP is run as CGI, or FastCGI rather than mod_php.

My knowledge of the command line is just enough to make trouble for myself and the support team.

As the Symfony documentation stated I checked the CLI php version and found it to be 4.4.9 using php -v and that the configuration would not work with Symfony.

I had a look in the DreamHost Wiki and found this could be fixed by adding an alias to your path.

DreamHost by default has PHP installed with the option to run php 5.

  • PHP 4 – /usr/local/bin/php
  • PHP 5 – /usr/local/php5/bin/php
  • PHP 5.3 – /usr/local/php53/bin/php

Open your .alias file using FTP or command line.

Add the following alias to the bottom of the file.

alias 'php=/usr/local/php5/bin/php'

This should work for any web-server but the path will be different.

Work with RSS feeds using PHP and cURL

cURL or Client URL Library is a very powerful tool, and its something that i recently had to use while working with two APIs one for Unfuddle and one for HelpSpot.

PHP supports libcurl, a library created by Daniel Stenberg, that allows you to connect and communicate to many different types of servers with many different types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols. libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading (this can also be done with PHP’s ftp extension), HTTP form based upload, proxies, cookies, and user+password authentication.

These functions have been added in PHP 4.0.2.

You can interact with most APIs using cURL, at first it seams intimidating but once you start to use it you become comfortable with the set up.

Lets get started by parsing an RSS feed.

Continue reading “Work with RSS feeds using PHP and cURL” »

Php Microtime

This is a handy bit of code that will help when optimizing your script. Most MVC or NonMVC frameworks have a benchmark feature but if you are on your own this will do just fine.

The PHP microtime() function will return the current Unix timestamp.

There isn’t much to this script, we are going to assign $time-start the start time. Then below your code to time place the $time_end.

A little simple math will tell us the difference. $time-start minus $time-end will give us the execution time.

If we were to use the raw result we would see something like this: 0.0562338829041 Seconds.

Its a bit to detailed do be of any use. We can use the PHP Function round() to round the number to 3 decimal places.

$time_start = microtime(true);

// Code Here
for ( $counter = 1; $counter <= 1000000; $counter += 1) {
	$counter;
}

$time_end = microtime(true);
$time = $time_end - $time_start;

echo "Loaded in ".round($time, 3)." seconds\n";

That’s it!