ปัจจุบันการพัฒนาระบบงานด้วยภาษา PHP
น่าจะใช้งาน Composer สำหรับจัดการเรื่อง library หรือ dependency ต่าง ๆ
ปัญหาหลักของ composer คือ ความช้า
เนื่องจาก composer จะทำการ download สิ่งต่าง ๆ
มาจาก Packagist :: The PHP Package Repository
ดังนั้นสิ่งที่เราต้องการคือ ปรับปรุงให้เร็วขึ้น
ด้วยการติดตั้ง Repository repository เองไปเลย
โดยสิ่งที่เราจะใช้งานสำหรับสร้าง Composer repository คือ Satis
มาเริ่มกันดีกว่า
ก่อนอื่นมาดูโครงสร้างการทำงานปกติของ Composer
แสดงดังรูป
จากนั้นทำการติดตั้ง Satis repository
เพื่อทำการเก็บข้อมูลของ library และ dependency ต่าง ๆ ไว้
ทำให้ไม่ต้องเสียเวลาไปดึงข้อมูลมาจาก Packagist
ทำให้ทำงานได้รวดเร็วขึ้น
แสดงการทำงานดังรูป
หรือถ้าวาดเป็นขั้นตอนการทำงานแสดงดังนี้
ทำการติดตั้งดีกว่า
เริ่มจากติดตั้ง Satis ด้วยคำสั่ง
$composer create-project composer/satis --stability=dev --keep-vcs
จากนั้นสร้าง configuration ของ Satis
เพื่อกำหนดค่าต่าง ๆ ของ repository เช่น
- ชื่อและ url ของ repository
- รายชื่อของ library ต่าง ๆ ที่ต้องการเก็บไว้ใน local repository
โดยสร้างไฟล์ชื่อว่า satis.conf ดังนี้
ทำการสร้าง repository ของ Satis ชื่อว่า packages-mirror
ด้วยคำสั่ง
php ./satis/bin/satis build satis.conf packages-mirror
ทำการ Start Satis ขึ้นมาด้วย PHP Build-in server
ด้วยคำสั่ง
php ./satis/bin/satis build satis.conf packages-mirror
ทดสอบเข้าใช้งานผ่าน http://localhost:4680/ แสดงผลดังรูป
นำ Local composer repository มาใช้งานกันได้แล้ว
ให้ทำการแก้ไขไฟล์ composer.json
ด้วยการเพิ่ม url ของ repository เข้าไป
ดังนี้
ทดสอบด้วยติดตั้ง library ผ่าน composer ซะ
$composer install
แนะนำให้ลองปิด internet นะครับ
จะพบว่า composer จะทำงานได้รวดเร็วมาก ๆ
เพียงเท่านี้ก็สามารถติดตั้ง Local composer repository ไว้ใช้งานได้แล้ว
Reference Websites
https://getcomposer.org/doc/articles/handling-private-packages-with-satis.md
http://labs.qandidate.com/blog/2013/12/05/using-satis-for-fast-and-reliable-software-deployment/
http://blog.servergrove.com/2015/04/29/satis-building-composer-repository/
http://code.tutsplus.com/tutorials/setting-up-a-local-mirror-for-composer-packages-with-satis–net-36726
https://laravelista.com/satis-composer-repository-for-your-private-packages/