php while loop invoked remotely by cURL fails -


long-time user, first-time poster, patience!

this php code when invoked remotely through curl fails unless comment out while loop, of course defeats code's purpose of reading through file. fgets right file reading tool me, since file contains text lines ending in newline.

(i've created slightly-awkward construction using $readworks combine while , if clauses , enable code work when while loop commented out.)

<?php define( "ipdirfile", "path/to/ipfile.csv" ); // lookup in standard file location local lookups $readworks = true; $iplookup = fopen( ipdirfile, "r" ); if ($iplookup) { //  while ( $readworks ) { // uncomment loop produce failure     if (($ipline = fgets( $iplookup )) !== false) {         echo "got line fgets: " . $ipline . "<br>";     } else {         echo "can't fgets line<br>";         $readworks = false;     } } //} // ending brace  fclose( $iplookup );  ?> 

here's calling php code:

<?php $varstring = null;  $pgtcon = curl_init( 'http://domain/path/to/ipfinder.php' ); curl_setopt( $pgtcon, curlopt_connecttimeout, 30 ); curl_setopt( $pgtcon, curlopt_useragent, "mozilla/4.0 (compatible; msie 6.0; windows nt 5.1)" ); curl_setopt( $pgtcon, curlopt_post, true ); curl_setopt( $pgtcon, curlopt_returntransfer, true ); curl_setopt( $pgtcon, curlopt_ssl_verifypeer, false ); curl_setopt( $pgtcon, curlopt_followlocation, 1 );  // content below merely provides post $ipgeolocrequest = array(); // ip addresses pushed $ipgeolocrequest  foreach ( $ipgeolocrequest $ipidx => $ipval ) { // construct post data     $varstring .= $ipidx . "=" . $ipval . "&"; } $varstring = substr($varstring, 0, -1); // remove trailing ampersand  if (curl_setopt( $pgtcon, curlopt_postfields, $varstring )) {     $geodata = curl_exec( $pgtcon ); } else {     echo "option set failed<br>"; } curl_close( $pgtcon );  unset( $varstring );  echo $geodata . "<br>";  ?> 

per other posts i've ensured post string unset after curl call. top, remotely-invoked code works or without while loop when invoked locally through browser address bar. indicates, think, file opens , reads correctly, , script otherwise functional.

i'm brand-new curl, i'm sure i'm missing something! (it smells me times when miss glaringly obvious ;-)

why curl invocation cause php while loop fail?


Popular posts from this blog