Sending a xml request to other script
Posted: Thu Mar 12, 2009 12:51 am
Hi ,
I have 2 files as described below . I am sending a xml file as a string from send.php to recv.php .
The idea is recv.php gets the xml data and inserts in to database.
But when I execute the send.php through wamp server , it does not able to execute the recv.php script and it throws up the following message
==========================================================
Warning: file_get_contents(http://localhost/quick/recv.php) [function.file-get-contents]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\wamp\www\quick\send.php on line 21
Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\quick\send.php on line 21
=============================================================
I have set the allow url as file set to on in php.ini file.
Kindly guide me !
Regards,
Mithun
//send.php
<?php
$xmlfile = implode('', file('test.xml'));
$alternate_opts = array(
'http'=>array(
'method'=>"POST",
'header'=>"Content-type: application/x-www-form-urlencoded\r\n" .
"Content-length: " . strlen("$xmlfile"),
'content'=>"$xmlfile"
)
);
$context = stream_context_create($alternate_opts);
$result = file_get_contents("http://localhost/quick/recv.php", true, $context);
?>
//recv.php
<?php
$data = file_get_contents('php://input');
$dbh = new PDO("mysql:host=localhost;dbname=db_test", 'root', '');
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// debug
$res = $dbh->prepare("INSERT INTO employee VALUES('$data','30' ,'10' )");
$res->execute();
$dbh = null;
?>
I have 2 files as described below . I am sending a xml file as a string from send.php to recv.php .
The idea is recv.php gets the xml data and inserts in to database.
But when I execute the send.php through wamp server , it does not able to execute the recv.php script and it throws up the following message
==========================================================
Warning: file_get_contents(http://localhost/quick/recv.php) [function.file-get-contents]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\wamp\www\quick\send.php on line 21
Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\quick\send.php on line 21
=============================================================
I have set the allow url as file set to on in php.ini file.
Kindly guide me !
Regards,
Mithun
//send.php
<?php
$xmlfile = implode('', file('test.xml'));
$alternate_opts = array(
'http'=>array(
'method'=>"POST",
'header'=>"Content-type: application/x-www-form-urlencoded\r\n" .
"Content-length: " . strlen("$xmlfile"),
'content'=>"$xmlfile"
)
);
$context = stream_context_create($alternate_opts);
$result = file_get_contents("http://localhost/quick/recv.php", true, $context);
?>
//recv.php
<?php
$data = file_get_contents('php://input');
$dbh = new PDO("mysql:host=localhost;dbname=db_test", 'root', '');
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// debug
$res = $dbh->prepare("INSERT INTO employee VALUES('$data','30' ,'10' )");
$res->execute();
$dbh = null;
?>