Daniel Gafitescu Freelance web developer focused on open source solutions


Send SMS using AWS SNS

Usually I go with Twillio for sending SMS but AWS has a cheaper and easier solution for this.
Here is the code to send a sms using AWS SNS

First thing install aws/aws-sdk-php package

require __DIR__.'/../vendor/autoload.php';

use Aws\Sns\SnsClient;
$client = SnsClient::factory([
    'credentials' => [
            'key'    => 'your key',
            'secret' => 'your secret',
    'region'  => 'us-west-2',
    'version' => "latest"

$sent = $client->publish(
        'Message' => 'This is the message',
        'PhoneNumber' => '+123344545',
        'MessageAttributes' => [
            'AWS.SNS.SMS.SenderID' => [
                'DataType' => 'String',
                'StringValue' =>  'The sender'


Tagged as: , , No Comments


I wanted to see more statistics on my server over a period of time and one of the open source solutions was Collectd .

In order to view the graphics I installed Collectd-web which comes with a stand along python server that I can start when I want and just start ssh tunnel to see web page.



“Build APIs You Won’t Hate” & “Modern PHP: New Features and Good Practices”

Finish 2 books this holiday that I really like:

1. Modern PHP: New Features and Good Practices
If you are uncertain which programming language you like to learn and you are not sure if PHP is the right way this book will certainly change your mind.









2. Build APIs You Won't Hate

Last year most of my work evolved around API and specially building  REST API. This book gave me confidence that I am on the right track and also what I can improve when moving forward.

While driving I also listen to Rework which was a interesting as well.


​ O’Reilly – Up to Speed with PHP 7

Recently I had updated my VPS Php version to 7. It was easy and pretty smooth. I only had to add a single file so that WordPress would work with mysqli extension instead of old mysql extension which was deprecated.
I wanted to see what's new in Php 7 and I saw that O'Reilly had a course about it so I went and what it. Here is a short review of the course.

Php 7
- first major version release since PHP5 in 2004 after Php6 was abandoned in 2010
- is powered by a new engine PHPNG ( Php new generation)

Changes :

Internal changes
- according to Rasmus Lerdorf 100%+ performance on the most real-world apps
- lower memory usage
on Wodpress 4.1.1 PHP7 is slightly slower than HHVM 3.6.1
- simplifies creating add-on tools
- yield doesn’t require parentheses
- empty list() now allowed
- 64-bit integer support in Windows
- support for strings >= 2^31 on 64-bit builds ( video file conversion as string )
- very few breaks in backward compatibility
- most fatal errors now catchable ( Exception being thrown)
- mysql extension has been deprecated
- new json extension
- assert controller by configuration settings
- posix regex has been removed
- alternative php tags have been removed
- assign of new by reference has been removed

New operators:
- Spaceship operator ( already in Perl & Ruby )

$a = 6;
$b = $c = 10;
echo ($a <=> $b); ==> -1
echo ($b <=> $c ); ==> 0
echo ($c <=> $a) ==> 1

- Null coalesce operator

$variable = $non_existent ?? ‘default’ ;
also can be used in cascade
$var = $non_existent ?? $name ?? ‘default’;

Unicode escape syntax

$name = “Caf\u{00e9}” => Café

- random_bytes(20) ( Usage bin2hex(random_bytes(20));
- random_int(1,6) ==> generate a number between 1 and 6

Return type declaration
- is optional
prevent unintended return values
- forces sub classes to return expected data type

function convertor($string) : array {
return $array;

- Scalar type hinting
used for boolean (bool ), integer(int), float & string
- optional
- have 2 modes week & strong ( is done by declare(strict_types=1);
and needs to be first statement in the file

function multiply(int $a, int $b): int {
return $a*$b;

Anonymous classes
-can be assign to a variable
-return from a function
-pass as argument to a function
-extend a class , implement interface & use traits
- can’t be serialised

$testClass = new class() extends SplHeap {
protect function test($data1,$date2)
return ($data1 <=> $data2);

Generators return expressions

function generate() {
$total = 0;
for($i=1; $i<10;$i++) {
yield $i;
$total += $i;
return $total;
$counter = generate();
foreach($counter as $number)
echo $number;
echo “total = “. $counter->getReturn();

Generator delegation;
Binding to closures at call time;
Grouping Use Declarations

use SomeNamesSpace\SomePackage\SomeClass;
use SomeNamesSpace\SomePackage\SomeOtherClass;
use SomeNamesSpace\SomePackage\SomeDifferentClass;

Some as

use SomeNamesSpace\SomePackage\ {SomeClass, SomeOtherClass , SomeDifferentClass};

- Can be used for constants a function as well & even mix and match;

-catching fatal errors using Error class
-errors and expectations belong to different classes
-both implement the Throwable interface
-errors/exception can be catch in block

Other improvements
-improve security of unserialize;
-preserve 0 fraction when encoding as JSON

Tagged as: , , No Comments

CSS3 In-Depth from pluralsight.com

Watched CSS3 In-Depth just to see what's new in CSS3. Turns out there a lot of stuff but still some of them are not available in all browsers.

It's definitely a good watch if you are a front end developer.


Change field using migration on Laravel 4.2

If you have to change the type or in my case to add more options to the a ENUM field you need first to drop it and then to create it again (this will destroy the information in those field)

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class UpdateTableNameStatus extends Migration {

* Run the migrations.
* @return void
public function up()
Schema::table('table_name',function(Blueprint $table)

Schema::table('table_name',function(Blueprint $table)
$table->enum('status', array('PENDING','IN PROGRESS','COMPLETE'));



* Reverse the migrations.
* @return void
public function down()
Schema::table('table_name',function(Blueprint $table)


Schema::table('table_name',function(Blueprint $table)
$table->enum('status', array('PENDING'));



Became a Zend Certified Php Engineer


At the begging of 2013 I have read the article Become a ZCE in 2013 so I have set myself the goal that by the end of the year I should do be a Zend Certified Engineer. For the next 11 month I have totally forgot about it and in December I saw a tweet that said that Zend has upgraded the certification from Php 5.3 to Php 5.5 & rebranded from Zend Certified Engineer to Zend Certified Php Enginner so I bought a voucher.

The voucher is available for a year long so it gives you plenty of time to prepare for it, but I chosen the second to last day of the year to take it which was in fact the last day that I could schedule that exam. Ever since I have finished the university in 2008 I haven't taken an exam and I missed the thrill of going to one and even if I wasn't 100% sure I'll pass I went anyway. After the first 15-20 questions I was pretty confident that I was going to take it and in the end I wasn't sure on 4 questions , 2 of them were theory questions and the other 2 were code samples.

Advantages of being ZCE

  1. Proof that you are senior developer
  2. your future employ will be easier pursued into hiring you, and you can demand a raise on the current one
  3. looks good on your resume
  4. You will get to put a nice icon on your website ZCE logo to prove that you are certified and link it to Zend Yellow Pages.
  5. fill in the gaps in your Php knowledge and learn new stuff so you can use later

Testing system

I quite liked the testing system which was quite simple and intuitive. You have to answer 70 questions in 90 minutes , so you have around a minute and 30 seconds per question which is quite enought. Most of the time the question that are theoretic can be answer just in few second and you should take the time left to focus on the code sample ones.

If you are not sure of an answer you have the option to mark it for review and go back to it whenever you like, and even if you forget about it when you finish the exam you are asked to check again the marked for review questions. I was given 2 sheets of plastic paper that can be easily erased and 2 markers if you need to write something down other than that you can have anything with you.

As far as I recall around 15-20 question are from the new material starting with Php 5.4. Even if there are 70 questions in one question you are required to know the theory from several topics so they will cover the whole spectrum.

If you fail the exam they give you a report on specific topics that you lack knowledge so that you can improve on them next time but they don't give you the specific questions that you failed.

In order to find a test center you can access Zend Technologies Certification Testing from Pearson Vue but most likely you'll find one if you live in a big city.

Type of questions

There are 3 types of questions:

  1. Single answer. You are given 4 options in which just one is correct. Most of the question are like this type
  2. Multiple answers. You are given at least 4 options in which at least 2 of them are correct.This type of question are marked as multiple and you can easily figure it out because you get checkboxes instead of radio buttons.
  3. Fill in the blanks. You are given a sentence that you have to word or a phrase. In one of the questions I was given it was require to give the name of a function (func_num_args). There are only 2 or 3 questions like this one.

Where to study from ?

  1. The main source is obviously is the official website: php.net
  2. Video training
  1. Books
  1. Blogs that you can find by googling ZCE


  1. Don't pay the full price for a voucher

There is always a coupon code that you can use and get at least 10% of the Zend PHP Certification Voucher and you can get it just by doing a simple search on google. I have used the coupon code CJ4ZEND which is around $15 off the total of 195 and the coupon still work today. Also if you fail the exam for the first time, the second time you want to buy the voucher you will have a discount.

  1. Zend Certification Study Guide

You get a pdf file to down in email once you buy the voucher but seems like the file is not there any more http://static.zend.com/topics/PHP-5-3-Study-Guide-v1.pdf . In this draft pdf file you got sample questions devided per chapter but from my point of view they were easier than the one from the actual exam

  1. Read the php docs on the ebook reader/table device

In my case I have download the the php documentation fromhttp://doc.php.net/downloads/epub/php_manual_en.epub as epub format and read it on my kindle where I can make notes with ease.

  1. Test Prep: Zend PHP Certification online course

There is a very expensive test preparation from Zend which cost $1000 including the examn voucher which from my point of view is quite expensive.

  1. Upgrade from PHP 5.3 Certified

In October 2013 at a Zend Conference in Paris the new certification has been announce and it included PHP 5.4 and 5.5 and keeping a lot of the question from the previous exam but you can easily apply for an upgrade if you are allready PHP 5.4 Certified. In my case I have waiting for the new Php 5.5 certification for quite a while and everytime I email Zend they replied that it was a working in progress and they didn't have a release date. The chapters has been upgraded as well and you can found them in Exam information section.


They way I prepared was quite simple: I allocated 4 hours per each chapter and I have started with the part that was most familiar with and increase the time on the chapters that wasn't that good at like regular expressions, SPL and Traits in my case. In order to pass the exam you should be flawless on the Php Basics and you must treat all the question here as a trap. Don't always go for the obvious answer especially that you have code that you need to check. In my mind come the example with the strpos function.

if (strpos('abcdefg','abc')){
    echo "found it!";
    echo "didn't find it..";

At first glance you would say that it will echo "found it" but if you pay closer attension the strpos will return 0 which will be cased to a false boolean so in fact it will show "didn't find it..".

For the SPL which I never used before I study from the php|architect's Mastering the SPL Library and was just frustrated that I didn't used this before but after looking and studying it now everything that I can do with SPL I am using it. Regular expressions were another chapter that I wasn't that familiar with and I payed more attention to it and to the php functions.

All the function regarding strings, array & file management you need to lean by heart if you don't know them by now and also the operator priority list is another part that you need to be familiar with.

For the XML chapter you got to deal with SimpleXml , DOM and for this the best aproach was to get a xml file and play with all the function and methods so you can get more familiar with it. I have got 5 question involving XML so practicing was very importing on this matter.

Where to go next

Working in our field where thing change with such a pace and new technologies and framework emerge so often it's hard to settle for a certain version or framework. You always have to learn & research so you be up to date, and this sort of certification prove that you do that and you are always trying to improve and move forward.

There are a lot of other test/certification that you can take. The most appealing for me right now it's the Sensio Labs's Symfony certification specially if you are working with Symfony 2. There is also the Zend Framework 2 certification that you can take also from Zend. There is also ThePHP Curriculum which look really promising and the fact that Sebastian Bergmann ( the PhpUnit creator) is behind the project.

Anyway if you are looking forward to take the exam good luck with it and if you allready have passed it please share your experience in the comments below.


PHP 5.5 First Look

A short title from Lynda.com about the new features of the Php 5.5 done by Jon Peck

The title will cover :

- installing the Php 5.5 on a VirtualBox machine

- generators using the yield operator

- dereferencing
echo "abcd"[2] ==> b

- finally keyword on the try/catch statement for cleanup operations

- password hashing using the functions  password_hash , password_verify & password_get_info

- Opcache  included by default, previously knows as commercial Zend Optimizer +

- usage of list in foreach statement

- check if a function return empty result using empty function and not throw an error

- normalizing a bunch of different functions like boolval , pack & unpack

- what has been removed/deprecated on the latest Php version

Filed under: Programming No Comments

Laravel4 snippets

1. Web server configuration

For Apache , Nginx & lighttpd



2. Optional route parameter


 return "Returning info from  {$country_name} ."; 

So when the url will be

 /country - I will display

Returning info from Romania

 /country/USA - I will display

Returning info from USA

3. Multiple filters

You can call multiple filter using the | pile line.

	'before' => 'auth|is_allowed', function()
  	 return View::make('gold'); }

Goodbye ExtJs/Sensha , Hello KendoUi

I loved ExtJs (new Sensha)  for a long time , but now seeing what KendoUI can do I think I will stick with it.

Maybe Introduction To Kendo UI from http://pluralsight.com can convince you too.

Tagged as: , No Comments