2010-10-05 4 views
1

Я в основном создал скрипт с помощью Curl и PHP, который отправляет данные на веб-сайт, например. хост, порт и время. Затем он отправляет данные. Как узнать, действительно ли Curl/PHP отправил эти данные на веб-страницы? "? Хост ="...PHP - Как проверить, действительно ли Curl отправляет/отправляет запрос?

$ fullcurl = $ Хост "& время =" $ время ";.?

Любые способы, чтобы увидеть, если они на самом деле отправил данные в этих URL-адресов на My MYSQL

ответ

0

для того, чтобы быть уверенным, что локон посылает что-то, вам нужен анализатор пакетов. вы можете попробовать wireshark, например.

Я надеюсь, что это поможет вам,

Джером Вагнер

+0

Нет, я слышал, что мне нужно регулярное выражение или curlopt. – Ray

+0

Здравствуйте. Думаю, я неправильно понимаю ваш вопрос. Какова связь между curl, выполняющим свою работу и mysql? –

+0

В основном завиток захватывает URL-адрес от MYSQL, а затем отправляет им данные сообщения. – Ray

12

Вы можете использовать curl_getinfo(), чтобы получить код состояния ответа следующим образом:

// set up curl to point to your requested URL 
$ch = curl_init($fullcurl); 
// tell curl to return the result content instead of outputting it 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 

// execute the request, I'm assuming you don't care about the result content 
curl_exec($ch); 

if (curl_errno($ch)) { 
    // this would be your first hint that something went wrong 
    die('Couldn\'t send request: ' . curl_error($ch)); 
} else { 
    // check the HTTP status code of the request 
    $resultStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
    if ($resultStatus == 200) { 
     // everything went better than expected 
    } else { 
     // the request did not complete as expected. common errors are 4xx 
     // (not found, bad request, etc.) and 5xx (usually concerning 
     // errors/exceptions in the remote script execution) 

     die('Request failed: HTTP status code: ' . $resultStatus); 
    } 
} 

curl_close($ch); 

Для справки: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

Или, если вы делаете запросы к какой-то API, который возвращает информацию по результату запроса вам нужно будет получить этот результат и проанализировать его. Это очень специфично для API, но вот пример:

// set up curl to point to your requested URL 
$ch = curl_init($fullcurl); 
// tell curl to return the result content instead of outputting it 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 

// execute the request, but this time we care about the result 
$result = curl_exec($ch); 

if (curl_errno($ch)) { 
    // this would be your first hint that something went wrong 
    die('Couldn\'t send request: ' . curl_error($ch)); 
} else { 
    // check the HTTP status code of the request 
    $resultStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
    if ($resultStatus != 200) { 
     die('Request failed: HTTP status code: ' . $resultStatus); 
    } 
} 

curl_close($ch); 

// let's pretend this is the behaviour of the target server 
if ($result == 'ok') { 
    // everything went better than expected 
} else { 
    die('Request failed: Error: ' . $result); 
} 
Смежные вопросы