Reputation: 3
#include <curl/curl.h>
#include <stdio.h>
int main(){
while(1)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, \
"http://192.168.0.120/test.php?r=09210&o=919292" );
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 60);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
sleep(15);
}
return 0;
}
This program does not run continuously, it stops updating the database with the values after a few days or hours. Of course, I have tested it by removing the data in the database and checked if it was updating or not. Can anybody help me?
Upvotes: 0
Views: 963
Reputation: 3921
Maybe you can try to move the init and cleanup outside of the while loop, to avoid unnecessary operations which may fail.
#include <curl/curl.h>
#include <stdio.h>
int main(){
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(!curl) {
return 1;
}
while(1)
{
curl_easy_setopt(curl, CURLOPT_URL, \
"http://192.168.0.120/test.php?r=09210&o=919292" );
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 60);
res = curl_easy_perform(curl);
sleep(15);
}
curl_easy_cleanup(curl);
return 0;
}
Upvotes: 1