6

In my application i have to send the sms to user while registration. But while inserting record in database i want to hit this url in browser.

Can any one suggest how to run this url at backgound

http://www.myurl.com/smpp/sendsms?username=XX&password=XX&to=XX&from=XX&text=Test

Joe
  • 15,205
  • 8
  • 49
  • 56
CodePlateau
  • 381
  • 2
  • 5
  • 18

9 Answers9

8

Well this depends on what you mean with background 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);
Daniel Figueroa
  • 10,348
  • 5
  • 44
  • 66
5
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.

MasterX
  • 61
  • 1
  • 5
2

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.

PovertyBob
  • 31
  • 4
1

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:

http://www.php.net/manual/en/curl.examples-basic.php

Jan Petzold
  • 1,561
  • 1
  • 15
  • 24
1
$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)

Abhinav
  • 11
  • 1
0

you could fork a child-process with the pcntl php extension.

(library that implements this: https://github.com/kriswallsmith/spork)

gries
  • 1,135
  • 6
  • 29
0

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".

Community
  • 1
  • 1
Sergi Juanola
  • 6,531
  • 8
  • 56
  • 93
0

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.

Antony
  • 14,900
  • 10
  • 46
  • 74
0

Ajax? Load that url inside a div with ajax while you save the record calling another php file with ajax.

rodripf
  • 575
  • 2
  • 11
  • 24