0

I have a php script running in a web server in order to perform some inserts into a database. This script receives some encrypted data, decrypts it and push it into the db.

The responsible to send this data is a C++ program (Running in Linux), this program will send a message of no more than 40 characters every 5 seconds.

I was thinking on call some bash script that opens the URL (http://myserver.com/myscript.php?message=adfafdadfasfasdfasdf) and receives the message by argument.

I dont want a complex solution, because I just need to open the URL, it is a unidirectional communication channel.

Some simple solution to do this?

Thanks!

1
  • Your solution seems reasonable given the constraints. Commented Feb 14, 2013 at 17:00

2 Answers 2

3

A more robust solution would be to use libcurl, which lets you open a http connection in a few lines. Here's the self contained example from the link:

#include <stdio.h>
#include <curl/curl.h>

int main(void)
{
  CURL *curl;
  CURLcode res;

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
    /* example.com is redirected, so we tell libcurl to follow redirection */ 
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

    /* Perform the request, res will get the return code */ 
    res = curl_easy_perform(curl);
    /* Check for errors */ 
    if(res != CURLE_OK)
      fprintf(stderr, "curl_easy_perform() failed: %s\n",
              curl_easy_strerror(res));

    /* always cleanup */ 
    curl_easy_cleanup(curl);
  }
  return 0;
}
Sign up to request clarification or add additional context in comments.

Comments

1

Since you don't need to parse the result of the HTTP query, you could just use system to call a standard utility like wget.

int retVal = system("wget -O- -q http://whatever.com/foo/bar");
// handle return value as per the system man page

This is basically the same as what you were thinking about, save the script indirection.

1 Comment

Thanks for the answers!! Finally I decided to use libcurl, very easy to use for my purposes :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.