一般会设置一个超时时间1S,就是说如果php那边在1S内没有返回给urlserver的话就忽略掉该请求,及不阻塞等待返回了,直接处理下面的操作。
现在php那边有时候会卡,这样一卡就无法再1S内返回消息给服务器
由于urlserver只是忽略了该连接上的请求消息,并不是断开了,所以php那边无法判断消息是否是正常发成功了还是如何
所以玩家积分消耗了道具没拿到的兑换问题无法通过php捕获服务器没有收到来做。
int connectURL(char * strUrl, char ** strResult) { *strResult = 0; if (strUrl == 0) { return 0; } CURL * pCurl; CURLcode res; int nReturn = 0; pCurl = curl_easy_init(); // init pCurl if (pCurl == NULL) { return nReturn; } res = curl_easy_setopt(pCurl, CURLOPT_ERRORBUFFER, errorBuffer); // set error buffer if (res != CURLE_OK) { goto error_return; } res = curl_easy_setopt(pCurl, CURLOPT_TIMEOUT, 1); // set time out s if (res != CURLE_OK) { goto error_return; } res = curl_easy_setopt(pCurl, CURLOPT_URL, strUrl); // set url if (res != CURLE_OK) { goto error_return; } res = curl_easy_setopt(pCurl, CURLOPT_WRITEFUNCTION, writer); // set write func if (res != CURLE_OK) { goto error_return; } p_buffer.current_length = 0; if (p_buffer.cstring) p_buffer.cstring[0] = 0; res = curl_easy_setopt(pCurl, CURLOPT_WRITEDATA, &p_buffer); // set result buffer if (res != CURLE_OK) { goto error_return; } res = curl_easy_perform(pCurl); // run if (res != CURLE_OK) { goto error_return; } else { nReturn = 1; *strResult = p_buffer.cstring; } error_return: if (nReturn == 0) { printf("[WARNING][%s][%d][%s] ", __FUNCTION__, res, errorBuffer); } curl_easy_cleanup(pCurl); return nReturn; }