9 Replies - 5629 Views - Last Post: 09 June 2011 - 06:46 AM Rate Topic: -----

#1 juggy7  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 47
  • Joined: 31-May 11

CURL operation timeout

Posted 07 June 2011 - 11:05 PM

Hi,
When the other server is curling my page xyz.php On contiune stress testing.My page xyz.php response
curl: (28) Operation timed out after 1001 milliseconds with 0 bytes received
# Request Example
	$strPost = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
	$strPost .= "<request>";
	$strPost .= "<type>login</type>";
	$strPost .= "<abc>21</abc>";
	$strPost .= "</request>";
	 
	## Following is in xyz.php
	$data = file_get_contents("php://input");
	$file = xml2array($data, 1, 'attribute');
	$type = $file['request']['type']['value'];
	$abc= $file['request']['abc']['value'];
	 $strResp = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
	 $strResp .= "<response>";
	    $dt = "";
	    switch(strtoupper($type)){
	        case "LOGIN":
	                    $dt.= "<type>".$type."</type>";
	                    $dt.= "<abc>".$abc."</abc>";
                    $data .= "<user>abx</user>";
	                    break;
	        default : $data ="";
	             
	    }
	    $strResp .= $dt;
	    $strResp .= "</response>";
	    echo $strResp;



Those any one have any idea about these.I have a linux server and using zend framework.

Is This A Good Question/Topic? 0
  • +

Replies To: CURL operation timeout

#2 pemcconnell  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 54
  • View blog
  • Posts: 472
  • Joined: 05-August 08

Re: CURL operation timeout

Posted 08 June 2011 - 02:49 AM

you probs want to look at the setopt CURLOPT_TIMEOUT

setopt
CURLOPT_TIMEOUT / setopt implimentation examples
Was This Post Helpful? 0
  • +
  • -

#3 juggy7  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 47
  • Joined: 31-May 11

Re: CURL operation timeout

Posted 08 June 2011 - 03:15 AM

pemcconnell ,

CURLOPT_TIMEOUT ya they have specify of 1sec .And in few case its responding well and few cases its showing error as time.
Was This Post Helpful? 0
  • +
  • -

#4 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 944
  • View blog
  • Posts: 2,353
  • Joined: 15-February 11

Re: CURL operation timeout

Posted 08 June 2011 - 05:38 AM

And the errors are....?
Was This Post Helpful? 0
  • +
  • -

#5 juggy7  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 47
  • Joined: 31-May 11

Re: CURL operation timeout

Posted 08 June 2011 - 05:40 AM

curl: (28) Operation timed out after 1001 milliseconds with 0 bytes received


Was This Post Helpful? 0
  • +
  • -

#6 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 944
  • View blog
  • Posts: 2,353
  • Joined: 15-February 11

Re: CURL operation timeout

Posted 08 June 2011 - 06:52 AM

Thought you were referring to a different error...

cURL isn't getting a response which could mean that you have errors in the script above that produce a blank page.

Which xml2array snippet\function are you using? Some of them don't reference the value of a node by using the value index.
Was This Post Helpful? 0
  • +
  • -

#7 juggy7  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 47
  • Joined: 31-May 11

Re: CURL operation timeout

Posted 08 June 2011 - 10:06 PM

I am using following function for xml2array
function xml2array($contents, $get_attributes=1, $priority = 'tag') {
		if(!$contents) return array();
		if(!function_exists('xml_parser_create')) {
			return array();
		}

		$parser = xml_parser_create('');
		xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8");
		xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
		xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
		xml_parse_into_struct($parser, trim($contents), $xml_values);
		xml_parser_free($parser);

		if(!$xml_values) return;

		$xml_array = array();
		$parents = array();
		$opened_tags = array();
		$arr = array();
		$current = &$xml_array;

		$repeated_tag_index = array();
		foreach($xml_values as $data) {
			unset($attributes,$value);

			extract($data);
			$result = array();
			$attributes_data = array();
			if(isset($value)) {
				if($priority == 'tag') $result = $value;
				else $result['value'] = $value;
			}

			if(isset($attributes) and $get_attributes) {
				foreach($attributes as $attr => $val) {
					if($priority == 'tag') $attributes_data[$attr] = $val;
					else $result[$attr] = $val;
				}
			}

			if($type == "open") {
				$parent[$level-1] = &$current;
				if(!is_array($current) or (!in_array($tag, array_keys($current)))) {
					$current[$tag] = $result;
					if($attributes_data) $current[$tag. '_attr'] = $attributes_data;
					$repeated_tag_index[$tag.'_'.$level] = 1;
					$current = &$current[$tag];
				} else {
					if(isset($current[$tag][0])) {
						$current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result;
						$repeated_tag_index[$tag.'_'.$level]++;
					} else {
						$current[$tag] = array($current[$tag],$result);
						$repeated_tag_index[$tag.'_'.$level] = 2;
						if(isset($current[$tag.'_attr'])) {
							$current[$tag]['0_attr'] = $current[$tag.'_attr'];
							unset($current[$tag.'_attr']);
						}
					}
					$last_item_index = $repeated_tag_index[$tag.'_'.$level]-1;
					$current = &$current[$tag][$last_item_index];
				}
			} elseif($type == "complete") {

				if(!isset($current[$tag])) {
					$current[$tag] = $result;
					$repeated_tag_index[$tag.'_'.$level] = 1;
					if($priority == 'tag' and $attributes_data) $current[$tag. '_attr'] = $attributes_data;
				} else {
					if(isset($current[$tag][0]) and is_array($current[$tag])) {
						$current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result;
						if($priority == 'tag' and $get_attributes and $attributes_data) {
							$current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data;
						}
						$repeated_tag_index[$tag.'_'.$level]++;
					} else {
						$current[$tag] = array($current[$tag],$result);
						$repeated_tag_index[$tag.'_'.$level] = 1;
						if($priority == 'tag' and $get_attributes) {
							if(isset($current[$tag.'_attr'])) {
								$current[$tag]['0_attr'] = $current[$tag.'_attr'];
								unset($current[$tag.'_attr']);
							}
							if($attributes_data) {
								$current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data;
							}
						}
						$repeated_tag_index[$tag.'_'.$level]++;
					}
				}
			} elseif($type == 'close') {
				$current = &$parent[$level-1];
			}
		}
		return($xml_array);
	}


Was This Post Helpful? 0
  • +
  • -

#8 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 944
  • View blog
  • Posts: 2,353
  • Joined: 15-February 11

Re: CURL operation timeout

Posted 09 June 2011 - 06:37 AM

After some debugging the problem is the xml2array function returns null on the XML data you're attempting to pass. As for the TIMEOUT issue set CURLOPT_TIMEOUT to a higher value.
curl_setopt($ch, CURLOPT_TIMEOUT, 5);


Below's the file I used to send the POST request.
<?php
error_reporting(E_ALL);
define('POST', '<?xml version=\"1.0\" encoding=\"utf-8\"?><request><type>login</type><abc>21</abc></request>');

$ch = curl_init("http://localhost/xml2array.php");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, POST);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);

echo curl_exec($ch);

 if ( curl_errno($ch) ) {
        $result = 'ERROR -> ' . curl_errno($ch) . ': ' . curl_error($ch);
		echo $result;
 }
curl_close($ch);

?>


Then in your script I added this to view the data and realized xml2array was returning null even though the xml was in $data.
$data = file_get_contents("php://input");
$file = xml2array($data, 1, 'tag');
var_dump($data, $file);
exit();

Was This Post Helpful? 0
  • +
  • -

#9 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 944
  • View blog
  • Posts: 2,353
  • Joined: 15-February 11

Re: CURL operation timeout

Posted 09 June 2011 - 06:42 AM

I suggest parsing it yourself instead with DOMDocument
Was This Post Helpful? 0
  • +
  • -

#10 juggy7  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 47
  • Joined: 31-May 11

Re: CURL operation timeout

Posted 09 June 2011 - 06:46 AM

codeprada,
Thanks will implement and get back to you soon.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1