Wednesday, July 11, 2012

แก้ Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP


  หากใครเขียน PHP เพื่อทำการเชื่อมต่อผ่าน SSL socket เช่น ส่ง email ผ่าน SSL แล้วเจอข้อความแสดงความผิดพลาด (error message) แบบนี้ออกมา

unable to connect to ssl (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?) หรือข้อความที่ใกล้เคียงกัน
วิธีการแก้ปัญหานี้คือเข้าไปแก้ไขค่าใน PHP Configuration file (php.ini) ด้วยขั้นตอนต่อไปนี้
  1. เปิด php.ini สำหรับผู้ที่ติดตั้ง PHP ผ่าน App Serv Package ไฟล์นี้จะอยู่ใน folder C:\Windows
  2. ใน php.ini ลบ ; บรรทัดที่มีคำสั่งดังนี้ เป็นการเปิดใช้งาน php_openssl.dll extension
    1;extension=php_openssl.dll
    จะได้ผลลัพธ์เป็น
    1extension=php_openssl.dll
    บันทึกไฟล์ php.ini ที่ได้แก้ไขไป
  3. restart Apache Server สำหรับ App Serv ให้เข้าไปที่ Start > Control Server by Service > Apache Restart
  4. ทดสอบเรียกใช้คำสั่ง PHP ที่เขียนเชื่อมต่อ socket ผ่าน SSL ข้อความแสดงความผิดพลาดจะหายไป และทำงานได้ถูกต้องตามที่เราต้องการ