Penguins

IceMarkt

I thought I would say a couple of words about the open source project that I have been working on recently, IceMarkt. I’m not too happy with the name, I just wanted a unique name! A friend of mine recently mentioned that for marketing there was not a open source platform available, thus I decided why not try and start one. First things first, it would have to be able to upload and manage contacts. Secondly it must be able to email those contacts. And thirdly, the email content must be manageable. With this is mind, I created a CRUD for mail recipients and would send them all an email sent with Swift Mailer. The emails that were sent were a twig template. Because it was a standard twig file, this didn’t seem very usable for an end user. It was for this reason I decided to store the templates in a new table and then quickly add ckeditor to the page to make it more user friendly. At this point I realised that the end user would have to specify what the  email profile would be. i.e. who should the email say it is from and what are the reply to details. A quick another CRUD was created and Doctrine managed the one-to-many relation for me. (An email profile can be used on multiple templates, further to this, every email template must have a profile). Finally, to make sure that this wouldn’t be used for malicious spamming, I added a public facing bundle just so that I could provide and url for a user to unsubscribe from the mailing list. After all this worked end-to-end, I did my initial commit along with the Vagrant and puppet script I was using for my environment. (Yes, I cheated, I used puphpet.com !) With everything working, I started on the unit tests. Nothing worse than low code coverage from your tests! Once the unit tests were done, this allowed me to optimise IceMarkt an check that I wasen’t breaking it by accident! The biggest optimisation was to send the emails in batches so that if you had a very large contact list, the page wouldn’t time out. Now that this is done, I am refactoring the controllers so that doctrine is injected so that I can write unit tests instead of functional tests for my controllers. There are many things still left to do and realistically I just did this project because I want to play with vagrant, puppet and doctrine2 outside of industry. And it never hurts to add more to your portfolio. I am happy for anyone to volunteer and add to the project however I won’t merge anything in that breaks a unit test, doesn’t pass with PHPCodeSniffer set to PSR-2 or jslint errors when using the jslint config in the root directory! Features that still need implementing are:

  • Tracking – at the moment I’m relying on the user including google tracking codes in the markup of their email templates.
  • Custom fields for recipients – As anyone that uses IceMarkt will most likely want to store different types of information about a recipient custom fields seems appropriate.
  • Filter recipients for sending – Once custom fields are done it would be nice to query the recipients the receive the marketing so that it is no longer blind marketing! i.e. Only send to recipients where custom field ‘gender’ is ‘male’.
  • Authentication – Currently there is no authentication so anyone could add/edit/delete recipients, templates and profiles. I need to create a table of users and have a way to manage their roles.
  • Turn of mapping with NFS – as the VagrantFile is using NFS for the drive mapping, the VM will not currently work in windows.

IceMarkt can be found on github: https://github.com/irvingswiftj/iceMarkt

Alcaidesa

Toodles England, Ola Spain!

Time for a new venture. I have moved from the UK and now reside in Spain. A big change when you can’t speak the local language, however also a great opportunity to learn a new non programming language!

I hope this new move will mean that I’m out and about more than thus will be able to blog about fun activities and nice images as well as my normal programming rants!

SpotifyLibImg

My Spotify Meta Api Library for PHP

About 6 weeks ago I completed the first version of my library to work with Spotify’s Meta Api. However I realised that I had forgotten to mention it on my blog. You can view to source on github ( https://github.com/irvingswiftj/spotifyLib )

Features:

  • Search for songs/artists/albums/tracks on Spotify
  • get info on a song/artist/album/track by uri
  • Unit tests built with PHPUnit
  • Using composer for phpunit and guzzle dependency

Still to do:

  • Implement PSR-0 autoloading
  • Go through my code with PHP-cs!

Any feedback is always welcome.  I posted this on reddit, and I was really impressed with feedback from the community ( http://www.reddit.com/r/PHP/comments/20ju0v/created_a_php_library_for_using_spotifys_api/ ).

Setting up Xdebug’s remote debug with PHPStorm

Introduction

As promised in a reddit discussion, I thought I would put up an article on setting up xdebug’s remote debugger with PHPStorm. I have had to assist multiple developers in setting it up and I suspectits because there is a lack of ‘how tos’ on this topic on the interwebs.

I have broken this ‘how to’ into two sections, the server setup and the PHPStorm setup. In my case my server happens to be Debian, so if you are using a different flavour of linux, please adjust as necessary. Likewise with PHPStorm version, my screenshots are from version 7, as far as I can remember, they should differ since version 5.

The server settings

Firstly, check that you have Xdebug installed. My method of checking this is to run the following from terminal:

$ php -i | grep "xdebug"

If you get a result, fanstastic, else you will need to install xdebug, this should do it for you:

$ apt-get install php5-xdebug

Now you will need to change you php settings, so open the file /etc/php/conf.d/xdebug.ini (hopefully using vim and we all know that nano is an inferior editor!!!).

It should contain one line which will be the setting for the zend_extension. After that line add the following settings:

debug.remote_host= 192.168.0.10
xdebug.remote_port=9000
xdebug.max_nesting_level=200
xdebug.remote_enable=1
xdebug.idekey="PHPSTORM"
xdebug.remote_autostart = 1

N.B. if you are unsure of what your remote host IP address is, create a php file in which you echo $_SERVER['REOMTE_ADDR']; and run it from the machine you use PHPStorm with. It will output the correct IP address.

Finally, don’t forget to restart you web server (apache in this example):

$ service apache2 restart

The settings in PHPStorm

Go to your PHPStorm settings and make sure that you xdebug port is set to 9000 (if you can not use 9000, I sometimes 9124 else 9125; just make sure it is the same in you ini settings on your server).

PHPStorm Settings Panel
PHPStorm Settings Panel

Save those settings and now go to Run>Edit Configurations… where you will need to add a remote debug instance (see screenshot below)

add remote debug instance
add remote debug instance

You can name this remote debug instance what ever you want, just make sure the IDE key matches what is in xdebug.ini on your server (in this example we used ‘PHPSTORM’).

remote debug instance settings
remote debug instance settings

It likely you won’t have a server setup, if that is the case you can add one by clicking the ‘…’ button. In my project when adding a server, I always need to specify the mappings so you might find you have to do the same.

Finally, once have saved those settings, click on the listen button so that it goes from:

xdebug listening icon
xdebug listening icon

to:

xdebug not listening icon
xdebug not listening icon

If you add a breakpoint now, and load up the page that you want to debug, it should now stop at your breakpoint (I would probably test this with the first line of your index.php to make sure your breakpoint is getting hit!).

Hopefully you will now be a god at debugging the hardest of bugs!

Other hints

If you are not using xdebug, i highly recommend that you turn it off on your server, as if you computer is turned off and you access anything PHP via your webserver it will hang like make as it will be looking for the machine with the IP address specified.

I recommend that you check out xdebug’s profiler if you haven’t already and use it with a tool like kcachegrind else webgrind. Again, I would turn off profiling when not using it as the files it creates on each page load are vast and if you have a small server you may find you run out of storage very quickly!

My Lack of Blogging + Apology!

So, I have written anything to my blog for about 18months, one of my new year’s resolution is to blog more. I have notice that this site is painfully slow, hence new hosting is high on my list of priorities.

I was also tired of the old theme on this blog, so I have set it to WordPress’ new twenty fourteen theme until I rustle up the time to create something custom.

At least my resolution for this year was greater that 1024×768!

Quick Start guide to install LEMP server on Ubuntu 12.04 (Linux + Nginx + MySql + PHP )

I have seen some online guides about this but really was after one specific to Ubuntu 12.04. So here goes:

Step 1 – Installing Nginx

First we need to add the Nginx source

sudo add-apt-repository ppa:nginx/stable

Next, as we always do after adding a source, we need to update

sudo apt-get update

And now we install it

sudo apt-get install nginx

Next, we must start the Nginx service.

sudo /etc/init.d/nginx start

To check if it is successful, try going to http://localhost/ in your browser. If you see a Welcome to Nginx page, it has been successful.

Step 2 – Installing PHP5:

Install PHP and any required extensions

sudo apt-get install php5-cli php5-cgi php5-fpm php5-mcrypt php5-mysql

Edit the default Nginx site config (if you are not familiar with vim, try entering ‘nano’ instead)

sudo vim /etc/nginx/sites-available/default

The changes you will need to make are as follows:
1)

index index.html index.htm;

to

index index.html index.htm index.php;

2)

root /srv/http/nginx;

^this path may be different in your install, it doesn’t matter as we are changing it!
to:

root /var/www;

3) uncomment the following lines

 location ~ \.php$ {
     fastcgi_pass 127.0.0.1:9000;
     fastcgi_index index.php;
     include fastcgi_params;
  }

Now quit vim (‘:wq’) and restart the nginx service.

sudo /etc/init.d/nginx restart

If the folder /var/www/ doesn’t exist, create it

sudo mkdir /var/www/

Step 3 – Install MySQL

And finally,

sudo apt-get install mysql-server

Step 4 – Check it works!

Create a test file

vim /var/www/test.php

Add this line

<?php phpinfo();?>

Save and quit vim (:wq) and go to http://localhost/test.php in your browser.
If you see a page displaying all your PHP settings, then it works!

Ajax breaks in wordpress if back-end uses SSL

So you have a wordpress blog and you (or your client) want the wp-admin to use an SSL certificate, sounds great! However, any AJAX you use in your site has broken. I spent a while googling this issue when it happened to me and found a really easy fix; you need to change the variables in the get_admin_url() function to force the AJAX requestion to use http instead of https. Change it to look like:

get_admin_url(null,'','http');

I hope this helps a lot of people!

James Irving-Swift's portfolio and random blogging

Fork me on GitHub