tailieunhanh - Publishing AJAX and PHP - part 11

Lưu ý rằng các cuộc gọi file_get_contents không không đồng bộ, và họ không cần được. Các kịch bản PHP là không kết nối trực tiếp với người sử dụng, và nó có thể mất khi cần thiết để hoàn thành. Về phía khách hàng, các chức năng checkAvailability và getNumber nhận được những phản ứng này, chúng tôi đang tạo ra từ kịch bản PHP. | Server-Side Techniques with PHP and MySQL If the action is checkAvail ability we call elseif action CheckAvailability address of page that returns buffer level serverAddress http cgi-bin checkbuf received buffer level is in form x bufferPercent file_get_contents serverAddress extract the number buffer substr bufferPercent 0 strlen bufferPercent - 2 echo the number echo buffer Note that the file_get_contents calls are not asynchronous and they don t need to be. The PHP script isn t in direct connection with the user and it can take as long as needed to complete. On the client side the checkAvailability and getNumber functions receive these responses we are generating from the PHP script. The functions start by reading the response and checking its size handles the response received from the server function getNumber retrieve the server s response var response if the response is long enough or if it is void we assume we just received a server-side error report if 5 0 throw 0 Server error response This is a method to check whether the PHP script executed successfully. Deciding whether the execution was successful depending on the size of the response is quite a primitive but yet an efficient method. The fact that PHP throws those fatal errors that can t be caught and dealt with makes it hard to implement a generic powerful errorhandling mechanism. Apart from detecting the error in a commercial implementation you will also need to think very seriously what to do with it and the options are endless depending on your circumstances. Keep in mind that users don t care about the technical details of the error. In our scenario for example we could simply output a message such as The server is temporarily unavailable please try later. However if you want to output the exact error message consider that your custom-made errors use the n new line character while PHP s fatal errors output HTML .

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.