If you have been developing software with PHP for a long time, you may have noticed that it takes a lot of time to re-download, write, and try to use the current version of some libraries / files. If you are projecting using libraries such as Zend, Symfony and Laravel, you are in need.
What is this?
Composer is dependency management tool for PHP. If your project is heard, it will allow you to define libraries and install and update them for you.
How to use?
I assume you have php installed on your computer. I have XAMPP.
If you no have PHP you can download XAMPP this link.
XAMPP is a PHP development environment and free.
Windows
1) Download the Composer
Download
2) Installing Composer via setup
Select your php.exe path.
Click install and finish the installation.
Then open the CLI (command line interface ex. CMD) and write 'composer'. You will see Composer welcome screen.
Well finished the Composer setup. We can actually do some practice.
I created "composer-test" folder to "C:\xampp\htdocs\composer"-test on my disk.
Open the CMD and write this code.
Code:
cd "C:\xampp\htdocs\composer-test"
Packagist
Composer packages is here.
My choice is geerlingguy/ping
I want to use the package, I need to use the necessary commands.
Code:
composer require geerlingguy/ping
Okey ! Now this files on my "composer-test" folder
I created "index.php":
Code:
<?php
require_once __DIR__ . '/vendor/autoload.php'; // This is default Composer general including file. One require and included all packages :)
$host = 'www.google.com'; // Host
$ping = new \JJG\Ping($host); // Called package.
$latency = $ping->ping(); // Ping
if ($latency !== false) {
print 'Latency is ' . $latency . ' ms';
}
else {
print 'Host could not be reached.';
}
And finish:
Composer Cheat Sheet
Thanks.
Last edited: