Run url in background in php

Solution:
Well this depends on what you mean withbackground
I'm asuming however that you mean that the user won't be redirected to that page.
If I were you I'd go with cURL if you have it installed, since the only thing you seem to want to do is make an ordinary request, and maybe, read the response. The code below is untested but should give you a hint.
$req = curl_init();
curl_setopt($req, CURLOPT_URL,"theaddress_and_params");
curl_exec($req);
Answer
Solution:
public function get_url($url)
{
$cmd = "curl --max-time 60 ";
$cmd .= "'" . $url . "'";
$cmd .= " > /dev/null 2>&1 &";
exec($cmd, $output, $exit);
return $exit == 0;
}
it will call curl via cli. it will run in background.
Answer
Solution:
If you did that you would be exposing usernames and passwords in the URL (or headers). Have the user login in advance and use a session variable.
Answer
Solution:
Don't send this from the client side since every user would easily be able to "fake" the data by just loading your URL with some (potentially malicious) parameters. "username" and "password" are not protected at all and I'm sure your service would be down very quickly.
Instead, you could easily do this in the background (server-side) with PHPs curl functions:
Answer
Solution:
$url = 'http://yoursmsgateway.com/WebSMS/SMSAPI.jsp?username='.$smsuser.'&password='.$smspwd.'&sendername='.$smssender.'&mobileno='.$number.'&message='.urlencode($message);
echo $url;
$mystring = get_data($url);
//echo "hi!";
echo $mystring;
function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
You can try this code, But you have to install cUrl DLL file. Process to install CURL is given below:--
1.)open php.ini file
2.)Find this dll file---> ;extension=php_curl.dll
3.)Remove ; (semicolon)
4.)such as---> extension=php_curl.dll
5.)Save it (Ctrl+s)
Answer
Solution:
you could fork a child-process with the pcntl php extension.
(library that implements this: https://github.com/kriswallsmith/spork)
Answer
Solution:
Make an AJAX call as the user hits the submit button. This would cause the script at that URL to run in the background while your current PHP inserts the record in the database.
Answer
Solution:
Ajax? Load that url inside a div with ajax while you save the record calling another php file with ajax.
Answer
Solution:
I think that there is no such concept as multithreading (which in essence is what you are asking for), as everything in a PHP code runs incrementally, but you can get to a solution. See this and this questions and their answers.
The reason that there is no multithreading in PHP is because everything is processed in the server, and you, as a client, already receive a finished response, so "running on background" in PHP is the same as "running sequentially".
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: mysqli::real_connect(): (hy000/2002): connection refused
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.