I have a loop in a php file to HTTP_Request Server Via CURL->POST.
But I don't know if I'm missing any security considerations. Also, is there a better way to perform this http request?
<?php
$j = 0;
while ($j <= 1) {
$url = 'http://127.0.0.1/index.php';
$fields = array(
'input1' => 'variable1',
'input2' => 'variable2',
);
$postvars = http_build_query($fields);
$COOKIE_FILE_PATH = "/tmp/cookiescron.txt";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
curl_setopt($ch, CURLOPT_TIMEOUT, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: close'));
// execute post
curl_exec($ch);
// close connection
curl_close($ch);
$j++;
sleep(25);
}
?>
This executes 2 requests in around 25~30 seconds.