How to auto-update composer packages with webhooks


In the previous tutorial, created, published and used our own package, we saw that by default, packages don’t auto-update. This implies that whenever we update our repository where these packages are hosted, we need to manually login to Packagist and update this package manually by clicking the update button in our dashboard. This experience could be very tiresome, and we wouldn’t want to do that. Thus, the need to auto-update our packages on Packagist each time our packet repository changes.

In this tutorial, we will make that package we created in the last tutorial to auto-update, wherever there is a change in our git repository.

How to auto-update composer packages with webhooks

To achieve this, we will make use of Webhook feature in GitHub, whose functionality could be summarized as that of an  HTTP callback.

The concept of webhook could be easily understood, it is more of a http call back, an HTTP POST that gets fired whenever something happens by sending a simple event notification.

In our case, this HTTP POST will get fired automatically by GitHub anytime there is push to our GitHub repository.

#Activating Webhook on GitHub

To activate this feature on our package, we will follow the steps below:

  • We will navigate to GitHub, and open the repository that has our published package
  • On this page we will click on “Settings” at the menu bar.
  • Then from the nav bar on the left, Select the option Webhook.
Activating webhook on github

When the Webhook tab opens, we will have some couple of fields to fill, which includes: Payload URL, Content Type and Secret.

#Payload: This is a unique URL, that is specific to your package on Packagist.

#Content type: This specifies how we want GitHub to send our updated packages to Packagist.

#Secret:  This is a unique key generate by Packagist, to ensure that any data its receiving is fully authorized.

These three options could be gotten from our Packagist dashboard here.

Activating webhook on github-2

After filling in these fields, the above screenshot shows that GitHub has been successfully been integrated into our package on Packagist and will be automatically update each time our GitHub repository is updated.

Yahh! finally we have successfully made our package to be auto-updating. Don’t forget to like and share and comment on the comment section. Follow us on twitter for more updates.

Previous: Create, publish and use your first composer package
Next: Making libraries/packages installable using composer

Share this Tutorial / Exercise on : Facebook and Twitter

PHP: Tips of the Day

PHP: What is the difference between bindParam and bindValue?

Unlike PDOStatement::bindValue(), the variable is bound as a reference and will only be evaluated at the time that PDOStatement::execute() is called.

And execute

call PDOStatement::bindParam() to bind PHP variables to the parameter markers: bound variables pass their value as input and receive the output value, if any, of their associated parameter markers


$value = 'foo';
$s = $dbh->prepare('SELECT name FROM bar WHERE baz = :baz');
$s->bindParam(':baz', $value); // use bindParam to bind the variable
$value = 'foobarbaz';
$s->execute(); // executed with WHERE baz = 'foobarbaz'


$value = 'foo';
$s = $dbh->prepare('SELECT name FROM bar WHERE baz = :baz');
$s->bindValue(':baz', $value); // use bindValue to bind the variable's value
$value = 'foobarbaz';
$s->execute(); // executed with WHERE baz = 'foo'

Ref : https://bit.ly/2ZU0eys