I am trying to make a restricted webpage. I want to execute a remote php file which contains api information and curl code.
Here's my first code (restrict.php):
<?php
if (!empty($_POST['invitation_code']) ) {
$invitation_code = $_POST['invitation_code'];
$url = 'http://localhost/auth.php?invitation_code='.$invitation_code;
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_exec($ch);
curl_close($ch);
}
?>
Here's auth.php:
<?php
if (!empty($_GET['invitation_code']) ) {
$invitation_code = $_GET['invitation_code'];
$url = 'https://reqres.in/api/users/'.$invitation_code;
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$url);
$resultauth=curl_exec($ch);
curl_close($ch);
var_dump(json_decode($resultauth, true));
$result = file_get_contents($url);
$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $result;
fwrite($fh, $stringData);
fclose($fh);
}
I want to execute auth.php using curl from the first script and auth.php should work in background
Problems:
1) restrict.php is waiting for auth.php to execute. auth.php is not running in background.
2) auth.php is too slow and is responding after like 1 minute.
Any ideas what could solve my problem?
Thanks!