php: xdebug

Byphunsanit

php: xdebug

การเขียน unit testing หรือทำ uat โปรแกรมที่เขียนว่ามีข้อบกพร่องบ้างหรือเปล่า การ debug ใน php จะนิยมใช้ XDEBUG EXTENSION FOR PHP การติดตั้ง xdebug ใน xampp ไม่ยากเลย (ง่ายกว่าใน docker ตั้งเยอะ) ผมเคยเขียนการติดตั้งไว้ใน ตรวจสอบโค้ดและวัดความเร็ว PHP ด้วย xdebug แต่ไม่ได้อธิบายขั้นตอนอย่างละเอียดเอาไว้ ครั้งนี้จะเขียนวิธีอย่างละเอียด

การติดตั้ง xdebug

  1. download extension มาจาก XDEBUG EXTENSION FOR PHP | DOWNLOADS
    แต่ถ้าไม่แน่ใจ ทางผู้พัฒนาได้ทำ Tailored Installation Instructions ไว้ให้ แค่ copy หน้า phpinfo ของเว็บที่เราใช้มาวางใน textarea แล้วกด Analyse my phpinfo() output ก็จะได้ version และ config มาแล้ว
  2. นำไฟล์ .dll ไปไว้ใน php’s Extensions directory: เช่น C:\xampp\php\ext
  3. เปิดไฟล์ php’s Configuration File: เช่น C:\xampp\php\php.ini เพิ่มคอนฟิก
    [Xdebug]
    xdebug.profiler_append = 1
    xdebug.profiler_enable = 0
    xdebug.profiler_enable_trigger = 0
    xdebug.profiler_output_dir = "C:\xampp\tmp"
    xdebug.profiler_output_name = cachegrind.out.%t.%p
    xdebug.remote_enable = true
    xdebug.remote_handler = "dbgp"
    xdebug.remote_host = "localhost"
    xdebug.remote_port = 9000
    xdebug.trace_output_dir = "C:\xampp\tmp"
    zend_extension = "C:\xampp\php\ext\php_xdebug-2.5.5-7.1-vc14.dll"

    ด้านล่างของไฟล์

  4. เปิดและปิด Apache ใหม่อีกครั้ง

เปิดหน้า phpinfo อีกครั้ง ลองค้นหาคำว่า xdebug อีกครั้ง ถ้าเจอแปลว่าการติดตั้งเสร็จแล้ว

About the author

phunsanit administrator

    Leave a Reply