CURL with authentication in PHP

function curlPost($url, $data) {
$ch = curl_init($url);
$headers = array(
‘Authorization: Basic ‘. base64_encode(“username:password”)
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$response = curl_exec($ch);
if (curl_error($ch)) {
throw new Exception(curl_error($ch));

return $response;
$response = curlPost(‘’, [
‘test’ => ‘test’,



Dependency injection in Magento 2

Before diving in to the dependency injection we have to look in to an OOPS concept of “Coupling” and “Decoupling”

‘Coupling’ is a term that describes the relationship between two entities in a software system (usually classes).

When a class uses another class, or communicates with it, it’s said to ‘depend’ on that other class, and so these classes are ‘coupled’. At least one of them ‘knows’ about the other.

The idea is that we should try to keep the coupling between classes in our systems as ‘loose’ as possible: hence ‘loose coupling’ or sometimes ‘decoupling’ (although in English ‘decoupling’ would mean ‘no coupling at all’, people often use it to imply ‘loose coupling’ between entities).

White Screen no errors Magento 2

Compilation command

php  bin/magento setup:upgrade

php  bin/magento setup:di:compile

php  bin/magento setup:static-content:deploy -f

php bin/magento cache:clean

After running the above command if you face the blank page error for front end page and admin end page as some error like “Fatal error: Uncaught Error: Call to a member function setActive() on boolean”

If you face this error then clear var/cache folder and pub static folder

then run

php  bin/magento setup:upgrade

php bin/magento cache:flush

Configure Magento 2 in localhost to work faster for development purpose.

Follow the steps to make magento 2 to work faster in  localhost xampp

  1. Go to C:\xampp71\htdocs\magento2\app\etc\env.php change “MAGE_MODE => developer”
  2.  Go to Admin login dashboard Choose Store-> Configuration-> System -> Full page cache -> change “Caching Application” to Varnish cache.
  3. Go to admin login Click System Menu -> Cache Management -> Select all option and disable cache . so you dont want to run all magento commands while working in localhost.