php - fixing curl_exec hangs in Windows 8 apache -


i've been researching , experimenting problem while now, , have yet find workable solution, think it's time call help.

i've got problem curl_exec, on specific server. here's background, first:

  • cpu: intel core i7
  • ram: 64gb
  • os: windows 8.0
  • server: apache 2.4.4 x86 ts
  • php version: 5.5.1 x86 ts w/xdebug 2.2.3
  • curl version: 7.30.0

php code exhibits problem:

$input_vars = (!empty($_post)) ? filter_input_array(input_post) : array(); $url = 'http://192.168.1.100/geekcavecreations/morti/chatbot/conversation_start.php'; $qs = '?'; foreach ($input_vars $key => $value) {   $qs .= "$key=$value&"; } $qs= rtrim($qs, '&'); $url .= $qs; $bot_id = $input_vars['bot_id']; $options = array(     curlopt_useragent => 'program o xml api',     curlopt_returntransfer => true,     //curlopt_post => 1,     curlopt_maxredirs => 5,     curlopt_connecttimeout => 5,     curlopt_timeout => 5, ); $ch = curl_init($url); curl_setopt_array($ch, $options); //curl_setopt($ch, curlopt_postfields, $input_vars); $data = curl_exec($ch); $debug = curl_getinfo($ch); curl_close($ch); echo '<pre>data = ', htmlentities($data), '</pre><br>'; var_dump($debug); 

as can seen, i've tried both , post, , both give same results. timeout options listed above there script won't run indefinately. i've had hang on 3 hours before stop apache service stop hangup (just canceling in browser won't it). output script follows:

array (size=26)   'url' => string 'ht tp://192.168.1.100/geekcavecreations/morti/chatbot/conversation_start.php?say=hello&bot_id=1&convo_id=78a9s39gut34lurq055in5s6r4&format=xml' (length=141)   'content_type' => null   'http_code' => int 0   'header_size' => int 0   'request_size' => int 203   'filetime' => int -1   'ssl_verify_result' => int 0   'redirect_count' => int 0   'total_time' => float 5   'namelookup_time' => float 0   'connect_time' => float 0   'pretransfer_time' => float 0   'size_upload' => float 0   'size_download' => float 0   'speed_download' => float 0   'speed_upload' => float 0   'download_content_length' => float -1   'upload_content_length' => float 0   'starttransfer_time' => float 0   'redirect_time' => float 0   'redirect_url' => string '' (length=0)   'primary_ip' => string '192.168.1.100' (length=13)   'certinfo' =>      array (size=0)       empty   'primary_port' => int 80   'local_ip' => string '192.168.1.100' (length=13)   'local_port' => int 2546  data =  

(couldn't figure out better way of formatting that, sorry)

also on same computer several virtual machines, each different os/server/php versions, , same physical document root, located on host machine. these machines range windows 7/iis centos/apache 2.2, , other combinations, , of them, without exception, run same script without trouble, , output expected xml document. if run url in web browser, output follows:

<?xml version="1.0"?> <program_o>   <version>2.3.0</version>   <status><success>1</success></status>   <bot_id>1</bot_id>   <bot_name>morti</bot_name>   <user_id>1</user_id>   <user_name>seeker</user_name>   <chat>     <line>       <input>hello</input>       <response>and failed you, undefined. how you?</response>     </line>   </chat> </program_o> 

i've taken above xml output , saved file, , had problem script perform curl call on url saved xml file, , script works without problem @ point, created mock-up script creates simplexmlelement object, populates few new tags, , echo's asxml() output created object (essentially conversation_start.php does, far less complex), , same problem. code mock-up script below:

$xml = new simplexmlelement('<program_o></program_o>'); $xml->addchild('version', '2.3.0'); $status = $xml->addchild('status'); $status->addchild('success', '1'); $xml->addchild('bot_id', '1'); $xml->addchild('bot_name', 'morti'); $xml->addchild('user_id', '1'); $xml->addchild('user_name', 'seeker'); $chat = $xml->addchild('chat'); $line = $chat->addchild('line'); $line->addchild('input', 'hello'); $line->addchild('response', 'and failed you, undefined. how you?'); $output = $xml->asxml(); header('content-type: text/xml'); exit($output); 

i'm pretty @ wits end here. i've changed php versions, apache versions, tried countless suggestions i've found here on other issues curl freezing, found here, here , here, among double dozen or more others.

and i've written book present problem, have ask: how can curl keep hanging on windows 8 platform?

well, seem have gotten root of problem. seems when execute curl call same server script doing calling, and if both "caller" , "callee" scripts trying use same session id, deadlock occurs, causing both scripts wait till other releases session. ended adding test see if there's session id in use, , if so, calling script doesn't start session. if there no session id, caller starts session, obtains session id, destroys session, allows "callee" script unfettered access said session, removing deadlock situation. below code used this:

$convo_id = (isset ($request_vars['convo_id'])) ? $request_vars['convo_id'] : get_convo_id(); // stuff here function get_convo_id() {   session_name('program o xml gui');   session_start();   $convo_id = session_id();   session_destroy();   return $convo_id; } 

using method, works expected. sincerely hope proves useful others in future.


Comments