473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Can php be used for daemons like this?

I have a C++ program.

I would like it to send data to a web server.

A script on said server would interpret this data and make some changes to
an SQL database on the server.

Googling I can find examples where a perl script daemon is used to
update a database from external data and then php is used to extract the
data to create webpages. But the only examples I can find of php being
used for data input as opposed to retrieval is via web-page based forms.

I tried looking in the php manual for information, but I wasn't really
quite sure what I was looking for - I'm looking for information on which
language I should be learning, not for information on how to do something
in a language I already know.

I know that I could learn perl to do what I want, but learning
perl seems rather like overkill given my relatively simple ambitions.

Any advice?

Thanks,

James
Jul 17 '05 #1
8 1643
With total disregard for any kind of safety measures James Gregory
<ja****@f2s.com> leapt forth and uttered:
I have a C++ program.

<snip>

It's possible using PHP's socket functions. Take a look at some of
the user notes over at http://uk.php.net/manual/en/ref.sockets.php

--
Phil Roberts | Nobody In Particular | http://www.flatnet.net/
Jul 17 '05 #2
On Tue, 10 Feb 2004 14:29:40 -0600, Phil Roberts wrote:
With total disregard for any kind of safety measures James Gregory
<ja****@f2s.com> leapt forth and uttered:
I have a C++ program.

<snip>

It's possible using PHP's socket functions. Take a look at some of
the user notes over at http://uk.php.net/manual/en/ref.sockets.php


OK...I guess I'll learn php rather than perl then. Perl looks messy, php
looks like C with some extra twiddly bits.

Thanks,

James
Jul 17 '05 #3
[ my apologies first ... I only think I'm not goofing ]

James Gregory wrote:
I have a C++ program.

I would like it to send data to a web server.
OK. HTTP POST is probably your best bet (could be HTTP GET).

A script on said server would interpret this data and make some changes to
an SQL database on the server.
OK. Could also be a compiled C++ (or anything else) CGI program.
(snip) I know that I could learn perl to do what I want, but learning
perl seems rather like overkill given my relatively simple ambitions.
If you have control over the web server (and can install a CGI program),
I think you could get away with learning CGI for C++.

Any advice?


Learn PHP :-)
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #4
PHP has a way of slowly eating up more and more memory as it runs. So using
a PHP script as a daemon might not be a good idea. You might want to try
PHP5. The memory management is much improved.

Perhaps your C++ program can spawn an instance of PHP everytime you need to
make some updates?

Uzytkownik "James Gregory" <ja****@f2s.com> napisal w wiadomosci
news:pa****************************@f2s.com...
I have a C++ program.

I would like it to send data to a web server.

A script on said server would interpret this data and make some changes to
an SQL database on the server.

Googling I can find examples where a perl script daemon is used to
update a database from external data and then php is used to extract the
data to create webpages. But the only examples I can find of php being
used for data input as opposed to retrieval is via web-page based forms.

I tried looking in the php manual for information, but I wasn't really
quite sure what I was looking for - I'm looking for information on which
language I should be learning, not for information on how to do something
in a language I already know.

I know that I could learn perl to do what I want, but learning
perl seems rather like overkill given my relatively simple ambitions.

Any advice?

Thanks,

James

Jul 17 '05 #5
James Gregory wrote:
I have a C++ program.

I would like it to send data to a web server.

A script on said server would interpret this data and make some changes to
an SQL database on the server.


Have you written the C++ program and therefore have control over where
it sends the data?

If so, why can't you just have a PHP script sitting on the web server
(as a web accesible page) that receives the data in a normal HTTP manner
and updates the DB?

Cheers,
Andy
Jul 17 '05 #6
On Wed, 11 Feb 2004 15:06:40 +0000, Andy Jeffries wrote:
Have you written the C++ program and therefore have control over where
it sends the data?
Yes...
If so, why can't you just have a PHP script sitting on the web server
(as a web accesible page) that receives the data in a normal HTTP manner
and updates the DB?


Well, I don't know, as I don't fully understand how all this CGI
stuff works right now - as I fully admit, I'm not really sure what I'm
talking about yet.

When you hit the "Send" button on an html form, I'm still not quite sure
what it does, as all the tutorials I can find sort of say "when you
click send <some magic stuff happens>, and then your
cgi program named in the html form is run".

There are tutorials and free libraries for CGI and C++ and php and such
like everywhere, but they are all about how to deal with the input of html
forms, rather than what http post actually means.

Does http post/get simply send a packet to the server with headers to the
effect of "Please run CGI program x.cgi and return the output to my IP x"?
So it would be possible to write a program that could automatically fill
in anyone's web form, anywhere?

If this were the case, then I see what you mean, all I would need to do
would be to work out what the right headers look like.

If this isn't the case, I don't understand what you mean.

James
Jul 17 '05 #7
James Gregory wrote:
Does http post/get simply send a packet to the server with headers to the
effect of "Please run CGI program x.cgi and return the output to my IP x"?
So it would be possible to write a program that could automatically fill
in anyone's web form, anywhere?
You're right!

If this were the case, then I see what you mean, all I would need to do
would be to work out what the right headers look like.


I don't know the exact details about the HTTP protocol
( see http://www.w3.org/Protocols/rfc2616/rfc2616.html )
but a POST request, in terms of what the client sends to
the server looks like (I never tried it, though):
POST http://www.example.com/path/to/program HTTP/1.0
User-Agent: My C++ Application/0.97.1 beta
Cookie: id=76a53fd5027c000
Content-Type: application/x-www-form-urlencoded
Content-Length: 28

name=Pedro+Graca
After that, on the server side, I have no idea how the program
"path/to/program" receives the "name=Pedro+Graca"
You might try a GET with telnet, to get a feeling for how it works :)
Start telnet
] telnet www.example.com 80
wait for the server to tell you it's ready (Escape character is '^]'.)
Type the GET and two ENTERs
] GET / HTTP/1.0
]
Your Request is successful (hopefully)
you might try to send a few more details along with the page you want:
] GET / HTTP/1.0
] Cookie: test=true
] X-perimenting: true
]

--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #8
On Wed, 11 Feb 2004 22:52:16 +0000, Pedro Graca wrote:

<snip>

OK, thanks for all that. I guess I'll just play about with the stuff from
the RFC and see what makes it work.

James
Jul 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: pranab_bajpai | last post by:
So I want to define a method that takes a "boolean" in a module, eg. def getDBName(l2): .... Now, in Python variables are bound to types when used, right? Eg. x = 10 # makes it an INT...
4
by: maricel | last post by:
Could someone confirm which tablespace is being used when running ALTER & CREATE INDEX. Is it the tempspace or the tablespace where the table resides? Many thanks, maricel
4
by: sdistefano | last post by:
Hey people! For the first time I'm doing a client/server application, and I'm really confused with IPC stuff. I read the fastest method is shared memory, but I tryed mmap and found it tedious...
2
by: gnewsg | last post by:
Hi all. I've just finished to write an FTP daemon in Python. To do things well I'd like to write an 'insteller' to permit the end user to 'deeply' install the package inside the system. In details...
11
by: Greg | last post by:
How can C# be used for a website ? Would the person viewing a site need to have the .NET framework installed ? What other technologies would need to be used ? Would a database server be needed...
0
by: Andrey | last post by:
HI i have a newbie question about the file() function. I have 2 daemons running on my linux box. 1 will record the IDs to a file - logs.txt other 1 will open this file, read the IDs, and then...
3
by: PurpleServerMonkey | last post by:
Seeking feedback from group members on a design I'm looking at using in a project. I've created an XML-RPC server and a number of Daemons, the idea is that the XML-RPC server gets a request from...
5
by: Jeffrey Barish | last post by:
As per Stevens/Rago, "file and record locking provides a convenient mutual-exclusion mechanism". They note the convention of putting the lock file in /var/run in a file called <name>.pid, where...
0
by: Cameron Simpson | last post by:
On 12Nov2008 14:07, Jeff McNeil <jeff@jmcneil.netwrote: | On Nov 12, 4:57 pm, Jeffrey Barish <jeff_bar...@earthlink.netwrote: | As per Stevens/Rago, "file and record locking provides a convenient...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.