Archive for February, 2014

It’s nice being able to use some of the features of Zend Framework in your old plain PHP projects. I’ve been doing this for a while, using a zend_init.php file which is almost like the index.php in the ZF public folder:

// Define path to application directory
 || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application/application'));

if($_SERVER['SERVER_ADDR'] == '')
 $app_env = 'production';
 $app_env = 'development';

// Define application environment
 || define('APPLICATION_ENV', $app_env);
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
 realpath(APPLICATION_PATH . '/../library'),
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
 APPLICATION_PATH . '/configs/application.ini'

That allows you to use all sorts of things like new Zend_Pdf() etc.
However I was doing an AJAX post from our plain old PHP site and I wanted it to actually run the MVC stuff!

In order to run controller actions from a plain script I did this:

$fc = Zend_Controller_Front::getInstance();
$request = new Zend_Controller_Request_Http();
 'module' => 'default',
 'controller' => 'branches',
 'action' => 'cms-save-branch-update'

You now have the full power of Zend Framework at your disposal! Have a nice day!

Frustrated? sorted it. They should send in a pull request instead of just having their forked version out there. But lets get you started!

For the impatient:

Sign up for a free microsoft azure trial account. These will of course run out, but if its profitable enough, you might want to keep them running, who knows? Or if you don’t want to sign up, you’ll be doing this on your own linux I would presume. Anyway. In the azure control panel:
Create new virtual machines x3,
all ubuntu 13,
2 with 8 cores, 1 with 4 four cores
Download Putty if you are in windows, or open your terminals up if you are Mac or Linux
In Azure, go into virtual machines and choose Endpoints. This is the firewall bit
Add new Endpoint, give it anything for a name, put port number 4000 in both the boxes, ignore tick boxes and finish adding
(Do this for the port number of each pool you sign up to, 4000 is the port for, 17333 for
Find out the address of the vm in the azure control panel summary
Open up Putty
Choose SSH and connect to your azure address with username ‘azureuser’, and the password you set
(Do this for each of the three virtual machines. You will have three prompts in front of you. Now the real fun begins (x3))

sudo apt-get install build-essential 
sudo apt-get install automake
sudo apt get install libcurl4-openssl-dev 
sudo apt-get install libjansson-dev 
sudo apt install git 
git clone 
cd cpuminer 

At this point the instructions for compiling the source code are displayed. Copy and paste (don’t type or copy from here(I think its a character ending issue on different os’es and machines)) the following lines:

./configure CFLAGS="-O3" 

Once you’ve done that, the source code is ready. Lets test we can mine. We assume btw you have a wallet address, if not, download one! The working wallet software has been released! But you can get started on the pool straight away.

Sign up for an account for Then add 3 workers, user1, user2, user3, all with password x.

Finally run this to test our mining capabilities in the pool!

./minerd -a keccak -o stratum+tcp:// -u maxpoinpoolusername.user1 -p x

Now if they are mining, which they will be if you followed this, then good. But if you close the putty session the mining will stop. So. Press Ctrl-C.

nohup ./minerd -a keccak -o stratum+tcp:// -u maxpoinpoolusername.user1 -p x &

Then press return when it looks like nothing is happening and you’ll see the command prompt again. It’s now running in the background.

Next time you log in through putty you change into the directory again

cd cpuminer

If you next log in and want to stop it, to say, switch pool, then you list processes and kill the miner process.

ps -ef | grep minerd

Take a note of the second number  in the line

kill [the number]

Now you can run ./minerd again with different credentials.
Thats you!
Have Fun!
See you on the moon!

XDebug your Production Server

I love IRC. My friend just doesn’t get it however. But he isn’t looking in the right places.

For instance, we are having a hellish time with our server migration in work today. Our site was transferred to a bigger better CentOS cPanel server, only to act very strangely and mess up. Checking logs only tells us so much, so I tried to get XDebug installed on the server. I was having issues, and so went into freenode and joined the ##php channel, where I was redirected to #xdebug, where I received direct help from XDebugs main contributor, Derick Rethans! You couldn’t ask for better assistance!

Anyway, lets get it installed. Log in to your server as root, and download the xdebug source code. Then run the following from within the source folder:

make install

Then edit your php.ini, with the following:
xdebug.idekey = PHPSTORM
xdebug.max_nesting_level = 250
xdebug.remote_log = "/home/allagent/xdebuglog"
xdebug.remote_host =

Now there are a couple of settings to be aware of. As I am in work and behind a router, connect_back = 1 wouldn’t work. If you can set up port forwarding on your router, then do so! And remove the remote host line. If not, we set it as 0, and set up an SSH tunnel. Derick sent me his blog link explaining how this is done so check it out here:

In PHPStorm (you are using storm, right?), goto your run/debug configurations and add a PHP Web Application. I called mine LiveDebug, but you can call it whatever you like. In the server drop down, add your server, tick use path mappings,  find your index.php, and stick in the absolute path for the same file on the remote server (something like /home/username/public_html/index.php). You should do the same with the document root, which means it shopuld find all the rest without having to manually set each page/file.

Now for the good bit! Set a breakpoint in your code by clicking to the left of the code but to the right of the line numbers. A red spot should appear to signify you wish to pause the code at that point for inspection. Click the Run menu, and click debug. Then select LiveDebug, or whatever you called it. a browser window should open, and in Storm the debug frame will pop out. Click the variables tab. You can see every variable as it is set at that line of code. To the right of the tabs you have buttons for skipping over code, and stepping into functions etc! Have fun!

Now hopefully I can figure out why this new server is acting up!