My code: {code...} This is not a very stable unified path. sometimes it succeeds and sometimes fails, and the wait time is too long!
My code
:
// Determine whether the remote file exists if (! Function_exists ('check _ url') {function check_url ($ url) {$ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_NOBODY, true); curl_setopt ($ ch, CURLOPT_FAILONERROR, true); curl_setopt ($ ch, CURLOPT_TIMEOUT, 10); $ res = curl_exec ($ ch); if ($ res! = False) {$ statusCode = curl_getinfo ($ ch, CURLINFO_HTTP_CODE); return $ statusCode;} curl_close ($ ch); return false ;}}
This is not a very stable unified path, sometimes the success or failure, and the waiting time is too long!
Reply content:
My code
:
// Determine whether the remote file exists if (! Function_exists ('check _ url') {function check_url ($ url) {$ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_NOBODY, true); curl_setopt ($ ch, CURLOPT_FAILONERROR, true); curl_setopt ($ ch, CURLOPT_TIMEOUT, 10); $ res = curl_exec ($ ch); if ($ res! = False) {$ statusCode = curl_getinfo ($ ch, CURLINFO_HTTP_CODE); return $ statusCode;} curl_close ($ ch); return false ;}}
This is not a very stable unified path, sometimes the success or failure, and the waiting time is too long!
Strange requirements: if the remote server is your own, you can simply write an interface on the server to check whether a file exists. If it is not yours, you can only check whether your network and the server-side network are fast and stable. just use your own method to write it.