Remotely execute a PHP script


Hi, guys !

I dunno if that topic has already been discussed here, but I couldn’t find any thread about it.

I have several modems (with a Q24+ chip) spread across town, and I need them to periodically write a value in a SQL database. In a first time, what I did was to open a FTP session and upload a file containing the value on the server. Then I have a cron task on the server that reads the file and insert its content into the database.

To avoid the FTP encapsulation, I thought about trying to do the same with a TCP connection : I manage to establish the TCP connection between the modem and my web server, but now I’d like to open a PHP script (passing the value with the GET method) that would automatically insert the value into my database. Does anyone know if it’s possible, and what commands I have to issue after connecting to the server ?

Or maybe you have a better idea on how to read/write a SQL database from a Q24+ modem ?



Surely, it’s just a matter of appropriately encoding it in the URI?

Could you POST the value instead?

This really has nothing to do with the Q24 modem!

You are just using (or trying to use) standard internet protocols - it is entirely irrelevant what device is used!

Check out the “HTTP made realy i[/i] easy” tutorial cited here: viewtopic.php?f=16&t=3269&p=12317&hilit=HTTP+Made+Realy+Easy#p12317


Thanks for your answer…

Well, I assumed it was a matter of protocole and not of component, but I was quite sure someone would ask me the type of modem I was using, so I answered before the question was asked. :wink: Anyway, I had a look at that tutorial you mentioned. It contains examples of what I want to do, which leads me to the conclusion I’m not totally insane and I can succeed. :laughing:

At that point, I send AT commands to my modem (with a PIC microcontroller) to open a TCP socket. I configure the GPRS, create the TCP client (AT+WIPCREATE=2,1,“my server”,80) and open the data connection (AT+WIPDATA=2,1,1). Now my point is (as I might have not said clearly enough) to tell the server to execute a script : from what I read on the page you are refering to, I must issue something like that :

GET www/script.php HTML/1.1
[blank line]

My first tests on a developpement kit and Hyperterminal are not really working, but I’ll make more tests tomorrow, sending commands from the microcontroller and not from a computer (I don’t like Hyperterminal much).

Anyway, thanks for those hints… Hope they’ll lead me to victory !!! :smiley:


I would suggest that you start without the microcontroller or modem at all, and just use some PC-based tools.
That way you can concentrate on the protocols without having to worry about the details of the microcontroller, modem, and the vagaries of GPRS…

Further down in that thread which I cited, davidc suggests a number of tools to do this - XAMPP, PuTTY, etc;
They all sound a bit UNIXy to me - I use Fiddler myself (see my reply to David).

Once you’re happy with what you need to send, and what to expect in response, then you can go back to worrying about the details of how to do it with your microcontroller, modem, and GPRS…



You are probably better off going straight to the POST method of pushing data - that way you are not size limited by your particular implimentation of GET.

Just remember that a POST request has a WRITE before the READ, and that the POST data also has to be URL encoded.

Have you been able write a php script to read the POST (or GET) variables from a form on a standard web page and insert them into your database? If not, get that working first, as you are simply going to be writing a very simple HTTP client on the Q24.

Don’t forget that your php script MUST return the appropriate header (i.e. 200 on sucess, 404 on error) to the client to indicate that the transaction is complete.

It looks like you are using the WIP library for the Q24. You’re probably not going to have to deal with (a) opening/closing the http connection & (b) sending the headers, as WIP will take care of this for you.

My recommended method of sorting this out:

  1. Write your PHP script to insert data into your database
  2. Test script using a conventional web browser (i.e. create a form with the correct fields and make your script the ACTION of the FORM) until it works as desired
  3. Use fiddler to intercept the browser comms with the server (or my notes on using PuTTY to manually connect to the web server) and take note of what is actually being passed up and down the wire
  4. Use the notes from the previous step and hyperterm (or your favourite serial terminal) to manually make the connection to the web server via the Q24 and the WIP application
  5. Once you have got the manual transfer happening, get your micro to format the data the same way and send it via the modem

good luck - it’s not that hard if you take things in small steps.

ciao, Dave


Hi (again) !

Ok, thanks for all those advices… I took things step by step (as davidc said) but I skipped some steps ! :blush: I’m not totally new to PHP and forms, so I had yet a working script to call. By the way, I stick to the GET method and not POST, cause the size of my parameters is not a limitation : my modem only needs to acknowledge it is still alive and check if it has datas waiting on the server, so the only thing it needs to transmit is its serial number.

I didn’t know Fiddler (seems I stopped reading the other thread a bit too early), but I installed it now, and I saw the HTTP request that causes my script to execute. Now I guess I just have to issue the exact same request by hand from any device (whether it is Hyperterminal or my microcontroller) to get the same effect… Even though it’s getting close to the week-end, I believe I can still do that. :laughing:

Hum, better not laugh before it’s actually done ! :unamused: I reached step 4 of davidc’s recommended method, but I can (and must) still do better. Wish me luck… :blush:



ARGH ! Stop the machines !!! Damn, my version of AT Commands User Guide was not up-to-date… :imp:

I didn’t know I could create an HTTP request directly with an AT command (AT+WIPCREATE=5,1,“my server”,80). Then I can send GET, PUT or POST requests quite easily. It’s way better than emulating an HTTP server through a TCP connexion. :laughing:

Ok, now I have another problem. I send an HTTP GET request to execute my PHP script, and I’m supposed to read on the UART the HTML code generated by the script (if there’s code). But I only get the very last lines of the code : for some reason, the beginning of the file is cut, as if the server had sent it before the modem was ready to receive. :cry: has anyone experienced that yet ?