When CURL fails

Every once in a while, as a programmer, you seemingly come upon a problem that flummoxes you, irritates you and takes you through a wide array of emotions – and in the end when you solve it, makes you look back and think, why did this issue even take so much time to fix.

Here’s one from my diaries: I was working for a client which dealt with lots of financial data, building an app which dealt with peer to peer wallet system and phone recharges. The app’s backend API was built using a custom PHP framework.

After having built the system, I went to my client’s office to deploy the system on their homegrown servers. One thing that I should mention is, being a company that handles lot of financial data – the entire campus was very secure. Regular audits, Access only to authorised personnel. But what struck me odd was that even the computers were not connected to Internet – A team of 20 programmers shared two computers that connected to Internet, which they used when they wanted to research the issues they were working on.

Having given a machine, I installed PHP on the servers and deployed my app – so I can start testing. This is where all the troubles started for me. For one of the methods, I had written some code to call client’s API to recharge their phone – but just no matter what happened, the API wouldn’t work.

Looking at the code, the code was written in a simple CURL snippet

// create a new cURL resource$ch = curl_init();
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);
// grab URL and execute it
curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);

But now here’s the funny part – the same URL was accessible via the browser, postman clients and everywhere. But through the code, it would simply refuse to work.

After looking into the logs – and learning more about CURL and how it works – I added the curl_error function to see what is failing this bit of code.

Error 7 – Bad request. Could not connect to host. 

Ah. So now we were getting somewhere. But there could be multiple reasons why we could not connect to the host – network dropping out, Internet not accessible and so on.

That’s when it hit me like a flash of light – The entire computers at the client’s office were passing through a proxy. Now the URLs worked perfectly because the browsers were configured. I opened a terminal and typed

curl -v www.google.com 

And truly enough – I got Error 7 again now. With a bit of more research – I was able to get it working. Adding these two lines to my code with the correct credentials got the code working.

curl_setopt($ch, CURLOPT_PROXY, “proxyurl:proxyport”);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, “username:password”);

And I ended my 12 hours of debugging this issue – being the more wiser about proxies and a deep understanding of CURL.

Homo Deus : A Brief History of Tomorrow by Yuval Noah Harari

Buy on Amazon

“Having reduced mortality from starvation, disease and violence, we will now aim to overcome old age and even death itself. Having saved people from abject misery, we will now aim to make them positively happy. And having raised humanity above the beastly level of survival struggles, we will now aim to upgrade humans into gods, and turn Homo sapiens into Homo deus.”

Yuval Noah Harari’s book Homo Deus is a book that doesn’t shy of making bold predictions about the future of humanity. Harari captures in detail what an apocalyptic future might look like centuries or even decades from now.

The book starts with detailing humanities’ current and past conditions, and slowly builds up to what will happen to us in future. In a year that saw Brexit, Trump – one tends to balk when he suggests that the world is a better place than what it was before, but YNH backs it up with solid proof. He points out that sugar is more dangerous today than gunpowder, and that more people die due to obesity than wars.

He effectively downplays the effect of a single political leader in solving global problems or to set a new path ahead for humanity.

The wildest dreams of Kim Jong-un and Ali Khamenei don’t go much beyond atom bombs and ballistic missiles: that is so 1945. Putin’s aspirations seem confined to rebuilding the old Soviet zone, or the even older tsarist empire. Meanwhile in the USA, paranoid Republicans accuse Barack Obama of being a ruthless despot hatching conspiracies to destroy the foundations of American society – yet in eight years of presidency he barely managed to pass a minor health-care reform.

He opines that the future is going to be controlled by billionaires who have tunnel vision about solving the problem plaguing humanity, namely – mortality and building conscious artificial intelligence systems. He terms this as “Dataism” – under which devices monitor everything about us. We will be connected to a central entity – which will suggest us better things, better tasks and eventually better mates.

But here is where it gets extra scary ( or comfortable – based on how you look at it), he suggests that what Homo Sapiens did to animals in the name of industrialisation (food production, rearing, etc) – will come back to haunt Homo Sapiens. He predicts, one day, all of us will be just biochemical beings who will be informed by this vast network of algorithms about how we feel from second to second.

My Review:

I think YNH makes a few bold claims in the book, and all of these ideas need to be taken with a pinch of salt.

For starters, he downplays the effect of billionaires who are out to solve global problems like diseases and inequality – The Gates Foundation’s efforts suggest otherwise.

He seems so optimistic about the IoT devices and, yet they have flaws that makes one wonder if they will ever reach the consciousness level. For ex:  late last year, there was a huge DDoS attack that happened due to these very devices, and well some of them are not really that smart.

But on the other hand, he does make a compelling point about how algorithms are ruling our lives and are taking away our jobs. Countries are now exploring basic income plans as we find ourselves marginalised because of faster robots and smaller silicon chips.

The entire chapter, where he demolishes the idea of consciousness is eerily captivating and there are many places throughout the book where his ideas will convince you in a similar fashion.

A fast-paced non-fiction, and definitely a must read book.