PHP and sockets

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
yagnbda
Forum Newbie
Posts: 8
Joined: Wed Oct 13, 2004 5:10 am

PHP and sockets

Post by yagnbda »

hi,
I have a problem and want help about it.
I want to execute a php script by a sockt application(built in c++), this socket application passes socket information to the php code which stores this information into MYSQL database.

I want to know

1-) how an application(not web application) can call php script located on remote location.
2-) how php provide interface so that another application(not web application) can pass parameter to php function.


I hope you people can help me.
thanks
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

the easiest solution:
change design from c++ -> php -> mysql to c++ -> mysql


you could also use a binary like wget/curl and then call that from c++ with the correct url (and post/get data).
yagnbda
Forum Newbie
Posts: 8
Joined: Wed Oct 13, 2004 5:10 am

Post by yagnbda »

No, i cant do this because i am to store my database remotly. i.e i will have to connect webserver on remote system and execute php located on that server. so i want to interact c++ and php
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Simply have the C++ script open a connection to the php script on the remote server - just like a browser does - and then pass the info along to it. You can use GET or POST and add a user/pass as well.
yagnbda
Forum Newbie
Posts: 8
Joined: Wed Oct 13, 2004 5:10 am

Post by yagnbda »

how to interact with php through c++, is there any specific way of interaction?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

i'll quote myself :p
timvw wrote:you could also use a binary like wget/curl and then call that from c++ with the correct url (and post/get data).
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Or you just create a socket in C++.
yagnbda
Forum Newbie
Posts: 8
Joined: Wed Oct 13, 2004 5:10 am

Post by yagnbda »

i have a socket already created in c++,
1) is there any way i can execute abc.php file on a remote computer through my c++ application
2) is there any way that a php function can get parameters from c++ application, if so then how c++ will pass parameter to php functions.
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

The php file must be run by the php interupter which is generally used with a web server. To run the file you have to mimic a web browser - so you connect to the server with the php file on whatever port the web server is running on and pass any varaibles you want to give the script through either POST or GET in the http protocol. The php script can then get this variables by:

Code: Select all

$_GET['some_var'];
$_POST['some_var'];
And you can therefor pass these variables around the php script as you wish.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

for the lazy, unwilling to code a http1 implementation

Code: Select all

int main(void)
{
  system("curl -d 'uid=myid&pwd=mypass&lang=en'  https://kuleuven.ac.be/weblogin.cgi");
  return 0;
}
Post Reply