I found out that some things can solve this problem -
1) Update your PHP version. Versions prior to 5.4.19 don't work I think. But just keep it to the latest.
2) Disable/Comment 'xdebug' in your php.ini file if its present. A link to disable it is present in the question.
3) If non of the above works then try this one. This worked for me finally after wasting an hour or so.
rm -rf vendor/ rm -rf composer.lock php composer install --prefer-dist
4) Rollback to a previous version of composer. It worked for some people. This might be a temporary solution ( because you definitely want to upgrade in future).
5) This one was killer. This one also worked You can create a SWAP memory using your hard disk. This means that memory in hard disk will be used as additional RAM but the access to it would be slower (just like normal hard disk access). This is more useful for EC2 instance users who have very less RAM. More information for this is here -