Results 1 to 4 of 4

Thread: ถาม: ปัญหาเกี่ยวกับการใช้ fsockopen() ของ PHP

  1. #1


    ผมใช้ function fsockopen() to connect to router via serial to ethernet converter
    โดยปกติแล้ว ถ้าเรา connect หา router โดยใช้โปรแกรมจำพวก hyper terminal ทั่วไป หลักจาก connect ไปแล้ว router ก็จะ return อะไรต่อมิอะไรกลับคือมามากมาย เพื่อที่จะให้เรา configulation

    แต่ที่ผมกำลังทำอยู่นี่คือ การ connect ผ่านทาง browser โดยใช้ภาษา php ขั้นแรกนั้นผมต้องการที่จะติดต่อไปยัง router ให้ได้เหมือนกับการใช้ hyper terminal เสียก่อน แล้วจึงค่อยทำระบบส่วนอื่นต่อไป โดยใช้โปรแกรมดังนี้

    $connection = fsockopen ("10.1.0.1", 2000);
    while(!feof($connection)){
    echo fgets($connection);
    }
    fclose ($connection);

    ปัญหาคือว่า โปรแกรมจะทำงานใน while loop จนกระทั่งถึง maximum execution time ก็จะหยุดทำงาน

    ช่วยอธิบายด้วยครับ แต่ผมของเปลียนจาก fsockopen() เป็น fopen() เพื่อทดลองการอ่านค่าจาก text file ธรรมดา ปรากฏว่าไม่ติด while loop ผมทำผิดตรงไหนรึป่าวครับ หรือมีอะไรแนะนำ ก็โปรดเถิดครับ ผมไม่รู้จะถามตรงไหน

    มีภาพแสดง output ให้ดูด้วยครับ

    error message: Maximum execution time of 20 seconds exceeded in


    [color=#33FF33]:: ความขี้เกียจ ทำให้คนเราโง่ ::[/color]

  2. #2
    Administrator asylu3's Avatar
    Join Date
    Jun 2000
    Location
    Thailand
    Posts
    3,557


    [code]<?php
    $fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
    if (!$fp) {

  3. #3


    เฮ้อ. . .ผมก็ดูมาจาก manual นี่แหละครับ แต่ว่ามัน connect to router ไม่ได้ connect to server
    มันไม่ต้องมีการส่งคำสั่งโดยใช้ fwrite() เพียงแค่ connect เข้าไปมันก็ส่งค่ามาให้ดังรูปแล้ว ... หรือว่าถ้าจะใช้ fwrite() ผมควรจะ write อะไรลงไปดีครับ ตอนนี้ติดแต่เพียงว่า มันเชคไม่ได้ว่าส่งมาหมดรึยัง เท่านั้นเอง
    ก็ใช้ feof แล้วหนิ ไมไม่ได้
    [color=#33FF33]:: ความขี้เกียจ ทำให้คนเราโง่ ::[/color]

  4. #4


    เนื้อหาเดียวกันกับกระทู้นี้

    http://citecclub.org/forum/index.php?showtopic=19484
    [color=#33FF33]:: ความขี้เกียจ ทำให้คนเราโง่ ::[/color]

Members who have read this thread : 0

Actions : (View-Readers)

There are no names to display.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •