 |
|
พอดีเขียนโปรแกรมส่ง SMS ซึ่งได้รับค่าพารามิเตอร์ทาง API มาเจ้าผู้ให้บริการ SMS Payment Gateway แล้วค่ะ
ได้ทดสอบ Code บน Host 2 ที่ และผลออกมาไม่เหมือนกันค่ะ คืออีกที่ 1 ได้ และอีกที่ ไม่ได้ (ที่ที่ไม่ได้เป็น Share Host ทั่วไปค่ะ)
ซึ่ง Host ที่ไม่ได้ จะขึ้นข้อความตามรายละเอียดด้านล่าง
Warning: fsockopen() [function.fsockopen]: unable to connect to xxx.xx.xx.xxx:80 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. )
เลยปรึกษาไปทางเจ้าของ Host ดังกล่าว ซึ่งได้รับคำแนะนำว่า ต้องเปิด Service บางตัว และถ้าเป็น Share Host จะค่อนข้างไม่ปลอดภัยในการเปิด
และอาจจะต้องใช้ Host ที่เป็นลักษณะของ VPS (แบบส่วนตัว)
ทั้งนี้ได้มาตรวจคำสั่งในบรรทัดตาม Error ที่แจ้ง
คำสั่งเป็นดังนี้ค่ะ
///////////////////// คำสั่ง
Code (PHP)
$fp = fsockopen("xxx.xx.xx.xxx", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$reqPkg = "POST /tunnel/servlet/sendSMS.do HTTP/1.1\r\n";
$reqPkg .= "Host: xxx.xx.xx.xxx\r\n";
$reqPkg .= "Content-type: text/xml; charset=UTF-8\r\n";
$reqPkg .= "Authorization: $authenHeader\r\n";
$reqPkg .= "Connection: close\r\n";
$reqPkg .= "Content-Length: " . strlen($postData) . "\r\n\r\n";
$reqPkg .= "$postData";
//echo "$reqPkg";
fwrite($fp, $reqPkg);
while (!feof($fp)) {
$respData .= fgets($fp, 128);
//echo "$respData";
}
fclose($fp);
}
$s1 = strpos($respData, "<status>")+8;
$s2 = strpos($respData, "</status>");
$code = substr($respData, $s1, $s2-$s1);
//////////////////////////////////////////
รบกวนปรึกษาค่ะ...พอจะมีทางอื่นที่ไม่ต้องใช้ Host แบบ VPS หรือเปล่าคะ เพราะ Host ลักษณะนี้จะมีราคาที่ค่อนข้างสูงกว่า Host แบบแชร์
หมายเหตุ : Host ทั่วไปสามารถเปิด Port ที่ส่ง SMS (ไม่แน่ใจว่าใช้ Port 80 หรือเปล่า) และเปิด Module แบบนี้ได้หรือเปล่าคะ
ขอบคุณค่ะ
Tag : PHP
|
|
 |
 |
 |
 |
Date :
2011-03-11 17:53:00 |
By :
oranuch |
View :
1636 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |