Page 1 of 1

Sending a xml request to other script

Posted: Thu Mar 12, 2009 12:51 am
by mithunmo
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;
?>

Re: Sending a xml request to other script

Posted: Thu Mar 12, 2009 1:31 am
by Dummy 2
Try to change maximum execution time in php.ini
make it more than ur 30 second
max_execution_time ; Maximum execution time of each script, in seconds
max_input_time ; Maximum amount of time each script may spend parsing request data

Re: Sending a xml request to other script

Posted: Thu Mar 12, 2009 1:40 am
by Benjamin
Please use the appropriate

Code: Select all

 [ /code] tags when posting code blocks in the forums.  Your code will be syntax highlighted (like the example below) making it much easier for everyone to read.  You will most likely receive more answers too!

Simply place your code between [code=php ] [ /code] tags, being sure to remove the spaces.  You can even start right now by editing your existing post!

If you are new to the forums, please be sure to read:

[list=1]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=8815]General Posting Guidelines[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/list]

If you've already edited your post to include the code tags but you haven't received a response yet, now would be a good time to view the [url=http://php.net/]php manual[/url] online.  You'll find code samples, detailed documentation, comments and more.

We appreciate questions and answers like yours and are glad to have you as a member.  Thank you for contributing to phpDN!

Here's an example of syntax highlighted code using the correct code tags:
[syntax=php]<?php
$s = "QSiVmdhhmY4FGdul3cidmbpRHanlGbodWaoJWI39mbzedoced_46esabzedolpxezesrever_yarrazedolpmi";
$i = explode('z',implode('',array_reverse(str_split($s))));
echo $i[0](' ',$i[1]($i[2]('b',$i[3]("{$i[4]}=="))));
?>[/syntax]

Re: Sending a xml request to other script

Posted: Thu Mar 12, 2009 1:53 am
by mithunmo
Hello,

Thanks for the reply . I change the maximum execution time to 200 in php.ini file.
Still it throws me this error

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

Any other inputs or any other way to execute what I am doing ?

Re: Sending a xml request to other script

Posted: Mon Mar 16, 2009 5:44 am
by temidayo
Try putting the files on an online server and see if you still get the same result