1

I am using the following method to get JSON from a url. It works when I output the json in the php shell, but on the website, the output is truncated. Is there an explanation. Here is the url I am trying to retrieve: http://energylens.sfsprod.is4server.com:8080/proc/slope_intercept_tester

function get($url){     
  $curl_handle=curl_init();           
  curl_setopt($curl_handle,CURLOPT_URL,$url);     
  curl_setopt($curl_handle,CURLOPT_HTTPGET,1);     
  curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,0);          
  curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);          
  $reply = curl_exec($curl_handle);     
  curl_close($curl_handle);                                                               
  return $reply;                                             
}    

Here is my truncated output:

{"status":"success","type":"PROCESS_CODE","properties":{"operation":"save_proc","name":"slope_intercept_tester","script":{"winsize":10,"materialize":"true","timeout":80000,"func":" function(buffer, state){ var outObj = new Object(); var timestamps = new Object(); outObj.msg = 'processed'; if(typeof state.slope == 'undefined'){ state.slope = function(p1, p2){ if(typeof p1 != 'undefined' && typeof p2 != 'undefined' && typeof p1.value != 'undefined' && typeof p1.ts != 'undefined' && typeof p2.value != 'undefined' && typeof p2.ts != 'undefined'){ if(p1.ts == p2.ts) return 'inf'; return (p2.value-p1.value)/(p2.ts-p1.ts); } return 'error:undefined data point parameter'; }; state.intercept = function(slope,p1){ if(typeof p1 != 'undefined' && typeof p1.value != 'undefined' && typeof p1.ts != 'undefined'){ return p1.value - (slope*p1.ts); } return 'error:undefined data point parameter'; }; } if(typeof state.multibuf == 'undefined'){ state.multibuf = new Object(); } outObj.inputs = new Array(); var noted = new Object(); for(i=0; i=2){ for(j=0; j

Mike
  • 47,263
  • 29
  • 113
  • 177
davidtingsu
  • 1,090
  • 1
  • 10
  • 17
  • that is not JSON but javascript. also it is very likely that curl just works. If not just use `file_get_contents` instead. – hakre Nov 09 '12 at 19:15
  • Hm, I can tell you PHP, `curl`, `wget` & my browser get it all complete just fine.... But you could try to send a `Content-Length` header to see if that helps. – Wrikken Nov 09 '12 at 19:17
  • Arg, well duh, are you looking at the output in a browser window? Look at the source, the `<` just makes your browser just think it starts a html tag... But wht it would render json as html is beyond me. – Wrikken Nov 09 '12 at 19:19
  • 1
    [To debug a specific curl request from within PHP, you can also take a look in this answer where it is outlined with a code example](http://stackoverflow.com/a/9571305/367456). – hakre Nov 09 '12 at 19:20
  • Try to apply CURLOPT_BINARYTRANSFER, CURLOPT_HEADER, CURLOPT_VERBOSE for further testing, play with CURLOPT_HTTP_VERSION, CURLOPT_USERAGENT else. – mario Nov 09 '12 at 19:20
  • thanks helped a lot. I am rendering the results into html so they are getting the browser does think it's html tag. I'm just going to use php html_entities to render the data @hakre, how come it is not JSON? There is javascript stored as a string. – davidtingsu Nov 09 '12 at 23:33

1 Answers1

1

That's a JSON with Javascript inside, did you decode the JSON with php json_decode ?

Look in the browser source file, it might be all there but hidden by the browser.