Base of PHP Development

This is my post for TopTal PHP Community. As I like to join Toptal as PHP website developer freelancer, I have written my post on base of PHP development. I’m fond of coding in PHP and like to work on Full-stack development on PHP Frameworks and wordpress.

While I’ve been researching other freelancing platforms, I came across and I immediately fell in love with it. Let me explain why I ended up liking it so much:

  • It’s the place where the best freelancers are – TopTal receives thousands of applications every month, but only about 3% of applicants get in. According to their website and various blog posts on the web, TopTal has developed a tough screening process to identify and accept the best engineers. Oh, and did I mention that the engineers who are accepted at TopTal work for clients such as Airbnb and ZenDesk?
  • Great blog posts – This is how I learned about TopTal in the first place. They have excellent posts on their Engineering Blog, written by freelance software engineers who work at TopTal. I’ve learned a lot from their blog, and I highly recommend that you try it for yourself.
  • Long term work – The only reason I don’t like freelance platforms such as Elance is that it’s hard to find long-term projects for a competitive salary there. Most of the projects are low-paying short-term projects, and you have to be on their site every day, so you can catch (on time) and apply quickly for the occasional good project that is posted there. That is boring, and very time consuming. TopTal promises to provide opportunities for you, so you don’t have to waste an entire day just searching for a good project.

We often receive requests on how to design applications for our hosting infrastructure. While there are a thousand different use-cases, many deserving of a different approach, the following is based on our experience and should be viewed as a guideline.

Many people are using modern full stack frameworks, such as Laravel 5, CakePHP 3, Symfony 2 or the like. Those already come with a set of style guides, patterns and recommendations.

However much is still up to the developer so here are our two cents on how a current PHP application development should be approached.

1. Code

The most important part of your application.


The code should be under version control. We go a step further and strongly recommend Git due to it’s wide spread and availability across the board (and because we are not aware of truly superior alternatives).


Adhering to defined coding standards will pay out: consistent code is better comprehendable by other members of a team and thereby adding new members is easier. No matter the size of the team (even for single developers): code maintenance can easily take up the majority of a projects time (thus money) and well formatted and documented code is the primary factor in reducing those efforts.

Also it’s just plain satisfying to read good code.

Open sourcing

Open sourcing your application code (or at least modularized parts of it) can be an extremely good idea: free hands to harden the code quality, free marketing for yourself or your company and supporting the community as a whole.

Again, we’d like to put an emphasis on Git. Using an exotic revision control it could be hard to find developers which are willing to spare the extra time.

The before mentioned style will also impact the level of acceptance and willingness to participate: using existing standards helps allows newcomers to jump right in without wasting time on deciphering your intentions.

2. Tests

Automated testing has long been the black sheep of the PHP family. However, this has greatly changed; the legend it would double development time is nearly rooted out and it’s now (luckily and) virtually unthinkable to contribute anything to most open source projects without a corresponding test.

A thoroughly tested application brings a lot of advantages. My personal top three:

Tested software can be far easier refactored
Unit testing enforces modular design (increased re-usability)
Tests provide a documentation and example code
There are lots of benefits but in the end for me it boils down to this: Better code — less headache.

3. Dependencies

Dependencies should (of course) be handled with Composer. Since the code is strongly coupled with specific package/library the dependency declaration (composer.lock) should be in the version control as well (in my opinion).

The actual package/library files (vendor folder) should not be part of version control, since their revisions are already handled by the declaration, which is thereby under version control and it would be redundant to do both.


Being a user of libraries/packages also changes your mindset (or at least positively re-enforces it) towards modularization of your own code. This in turn leads to less code repetition across projects and thereby reduces effort and increases quality in the long term. And let’s not forget the ability to open source those modules, as mentioned above.

4. Configuration

Configuration, if badly used, can be a great hindrance when migrating your application. More so, it can be a security risk.

Separate config from code

Using the environment is definitely the best choice. By this we primarily mean (operating system) environment variables but we think local configuration files (or a combination thereof) are a valid choice as well – as long as their deployment is clearly defined.

The best rule of thumb to measure whether the configuration is cleanly separated from the code we heard is: Could you open source your code without exposing any credentials right now? If the answer is Yes, then you are good.

Bad: in some

$database = "foobar";
$user = "foobar";
$password = "foobar";

Good: Environment variables from Apache SetEnv or the like:


Complex config

Environment variables can contain complex information (think: multi level array). It should be marshaled as JSON and encoded into base 64 so it is easily modifiable and readable from outside the application.

// somewhere in the bootstrap, assuming all encoded variables are prefixed with "::"..
foreach ($_SERVER as $k => $v) {
if (0 === strpos($v, "::")) {
$_SERVER[$k] = json_decode(base64_decode(substr($v, 2)));

5. Assets

Asset data, such as (compiled) CSS, Javascript, images and so on, are truly hard to decide upon. In short – and with limitations – my recommendation is to keep them under version control.

6. Runtime data

Runtime data includes all file based data (i.e. no databases), which is generated at runtime by user interaction (eg file uploads) or as an result thereof (eg multiple instances of an image). Classically this is handled using a local or network attached file system.

7. Resources

Resources are all services which are used by the application, such as databases, caches, queues, the afore mentioned storages, mail delivery providers and all that.


Access to resources should be abstracted. The degree of abstraction should depend on probability (eg if you are planing to scale out then you’d use an adapter for a local resource, which later will be replaced by an adapter for a network capable resource) and feasibility (eg a cache abstraction is almost always simple, while an abstraction allowing to substitute a MySQL database with, say, ElasticSearch much more effort, eg using the repository pattern, and this effort must be justifiable).

The location of resources must be substitutable by configuration (as described above).


$conn = new mysqli($servername, $username, $password);

The code will be tightly coupled to MySQL databases with a specific driver. If either MySQL databases or this driver is not available in a new environment the code must be refactored.


use Illuminate\Database\Capsule\Manager;
// $_SERVER['DATABASE'] = ["host" => "localhost", ...]
$mgr = new Manager->addConnection($_SERVER['DATABASE']);

Using a different SQL database can easily be achieved. Using a different MySQL database location can be easily configured.

Weak coupling

All “soft” services, without which the application still can run (eg a database driven application could not run without the database) should be dis-engage-able easily. Say a mail service is used to greet new users with a welcome mail: make sure you can switch it off with with a single command, in case the mail provider temporarily goes down. Even better: automate that. Best: Use a queue which can back-off and retry by itself.

8. Deployment

In a web application project, there are few things more feared, more disaster prone and hence over and over delayed than big upgrades into production. Deploy early and deploy often circumvents this by continuous integration of small upgrades. The primary requirement to allow this is a simple, transparent and fast deployment.

We are huge fans of Git based deployment, since it already comes with a history and allows easy integration of build scripts. However, application needs and environments differ greatly, so the perfect deployment for all situations is probably not to find.

Good code quality, testing and good measured abstraction pay out in the long run, having a easy to use deployment workflow is essential for the day in, day out work.

9. Stages

While automated testing provides a good foundation, when code meets content there is still lot’s of room for mishaps. Hence there is the concept of staging. Having a (working) local setup of the application already provides the first stage: the development stage (or local stage). The other stage, which always exists, is of course the production stage: the live web application. Now there is lot’s of space in between for testing, review and whatnot.

In general, all stages should try to approximate the production environment as closely as possible. The more they deviate, the less sense they make.

How many stages should be used depends on project size, team size, team setup, kind of application and so on. Please read a more comprehensive discussion here. As a general rule of thumb we recommend three stages: A local development stage, of course the production stage and a testing stage in the same environment as production (of course: separated).

10. Scalability

You probably have heard that you are now a DevOp. This means: when writing your application, you must be aware of the underlying infrastructure so you don’t fight with it’s weaknesses, but rather leverage it’s strength.

It’s a bit of a side effect of the cloud infrastructure. Before: all you had to do (and often could do) was vertically scaling your machine: bigger server. So you would not care as much where the bottle neck was, since there was only one solution. Now that you can not only scale out (horizontally), but do that for every resource individually, you should know which one slows you down. Or what you can do in terms of application design to compensate for that. Or especially: which new resource you can attach to boost the performance.

In short: You got access to the red button and with great power comes great responsibility.


It’s harder now: You must know more about coding patterns, deployment strategies, testing and application design than ever before. It’s easier now: a fleet of new tools, better services and coding standards help and support as never before.


ये ज़िन्दगी है तू

यादों में खोया न जागा न सोया, उनसे बिछडके रोया,
ये दुःख हमारा, ये सुख हमारा, गीतों में मैंने पिरोया।
एहसास मेरे रहे पास तेरे, मैं रहु ना रहु,
मेरा ये किस्सा है जीवन का हिस्सा, मैं ये कहु ना कहु,
मेरी नज़र का तेरी नज़र को सलाम,
होठों पे मेरे शाम-ओ-सवेरे तेरा नाम,
ये ज़िन्दगी है तू,
मेरा गीत मेरा मीत है तु.

पल पल ये आशा देती दिलासा, सफर है बाकि अभी,
नयी मंज़िले है नए फासले है, डगर है बाकि अभी,
मेरे साथ आओ, मेरे साथ गाओ, नयी उम्मीदे जगाओ,
हिम्मत तुम्हारी, है किस्मत तुम्हारी, तुम खुद ही आज़माओ,
मेरी नज़र का तेरी नज़र को सलाम,
होठों पे मेरे शाम-ओ-सवेरे तेरा नाम,
ये ज़िन्दगी है तू,
मेरा गीत मेरा मीत है तु.

By Amit Khanna (Movie: Star)

કેટલીક પંક્તિ ઓ..

રણ માં થશે વરસાદ આ નયનો માંથી,
ક્યાંક “આશ” નું વૃક્ષ ઉગી નીકળે રણ માં…

“આશ” હતી રણ માં વૃક્ષ બની ને છાયા આપવા ની,
પણ હવે ડૂબવું છે રણ માં તેની તરસ છીપાવવા..

દૂર જતું એક તણખલું, નિહાળી રહ્યો હું,
ક્યાં જઈ થંભશે? પવન માં ભટકી રહ્યું…

રમત રમી રહ્યો જીંદગી સાથે,
ખાલીપણા ને એકલતા મહી.
આવે યાદ “આશ” ને બંધ આંખે,
જે કેદ થઇ ગયા નજર મહી.

મન ના અરીસે ચાલી રહી પરીક્ષા,
પૂછી રહ્યું સવાલ, મારું પ્રતિબિંબ મુજને…


મંઝીલ ની રાહ પર ક્યાંક વાદળી વરસી ગઈ,
ક્યાંક મળ્યા કંટક તો ક્યાંક કાંકરી થઇ ગઈ..

એક કડી ક્યાંક ગુમ થાય છે જીંદગી ની,
ને રહી સહી “આશ” પણ ડગ-માગી જાય છે..

પ્રેમ કરી લે . . .

રસ્તે જાતાં પ્રેમ કરી લે,
હળતા મળતા પ્રેમ કરી લે.

રમતા ભમતા પ્રેમ કરી લે,
હસતા હસતા પ્રેમ કરી લે.

હોય ભલે ને અજાણ્યો જણ,
વાતવાત માં પ્રેમ કરી લે.

બધે હોય ના વસંત સુંદર,
પાનખરે પણ પ્રેમ કરી લે.

જીવવું તારે હોય જગત માં,
મડદાને પણ પ્રેમ કરી લે.

સગલાં ને તો સૌ કોઈ ચાહે,
દુશ્મનને પણ પ્રેમ કરી લે.

સુખિયાને ના પડી સ્નેહ ની,
દુઃખિયાને બસ પ્રેમ કરી લે.

ઊભો અલગ તું જઈશ સુકાઈ,
સઘળા સાથે પ્રેમ કરી લે.


ડો. બહેચરભાઈ પટેલ

કોશિશ માં છું

પોતા ને બેઠો કરવાની કોશિશ માં છું, 
એક ડર થી ના ડરવાની કોશિશ માં છું,
મારા થી ગભરાઈ ને ના ભાગો,
હું ખાલીપો ભરવાની કોશિશ માં છું,
આજ પતંગિયું ફરક્યું છે મારી પાસે,
આજ કાલ હું સુધારવાની કોશિશ માં છું,
અરીસો ના ધરજો ખુદ ને જોવા,
આજે ખુદ માં ઉતારવાની કોશિશ માં છું.


Lyrics of song DreamerOzzy Osbourne

Gazing through the window at the world outside
Wondering will mother earth survive
Hoping that mankind will stop abusing her sometime

After all there’s only just the two of us
And here we are still fighting for our lives
Watching all of history repeat itself
Time after time

I’m just a dreamer
I dream my life away
I’m just a dreamer
Who dreams of better days

I watch the sun go down like everyone of us
I’m hoping that the dawn will bring a sign
A better place for those Who will come after us …
This time

I’m just a dreamer
I dream my life away oh yeah
I’m just a dreamer
Who dreams of better days

Your higher power may be God or Jesus Christ
It doesn’t really matter much to me
Without each others help there ain’t no hope for us
I’m living in a dream of fantasy

If only we could all just find serenity
It would be nice if we could live as one
When will all this anger, hate and biggotry …
Be gone?

I’m just a dreamer
I dream my life away
I’m just a dreamer
Who dreams of better days
I’m just a dreamer
Who’s searching for the way
I’m just a dreamer
Dreaming my life away

Nahoti khabar

Nhoti khabar ke aag ma dubi javatu pan hashe,

Ne prem na dariya mahi salgi javatu pan hashe..

Chalya hata to raah par manzil chhatay na mali,

Joyu najar pachhi kari aam bhatki javatu pan hashe!