0

I have problems when I receive certain strings via the www class from a php file. At the php end, I echo a string and some strings freeze the Unity script that was making the WWW call (Unity 4.6.0). If I call the php file from the browser (direct url address) then it never gives any problems. The strings are always echoed fine.

The strings that I want to echo are the result of json_encode, but that shouldn’t matter. In my debugging mode, I have created a string that looks like the json_encoded string. Then I have tried different versions of the string, to see which ones freeze the calling app. So the php code ends like this:

$matches = 'one string’;
echo $matches;

See below the different strings I tried ($matches). DOES NOT WORK = this string freezes the calling app; WORKS = with this string the AJAX call is completed successfully, the app receives the data and moves on

$matches = '[{"Start":"2015-02-02 08:00:00","Duration":"15","nSituations":1}]'; // DOES NOT WORK
$matches = '[{"Start":"2015-02-02 08:00:00","Duration":"15"}]'; // WORKS
$matches = '[{"Start":"2015-02-02 08:00:00","nSituations":1}]'; // WORKS
$matches = '[{"Duration":"15","nSituations":1}]'; // WORKS
$matches = '[{"Start":"A","Duration":"15","nSituations":1}]'; // WORKS
$matches = '[{"Start":"2015-02-02 08:00:00","Duration":"15","nSituations":"1"}]'; // DOES NOT WORK (notice nSituations as STRING)
$matches = '[{"Start":"2015-02-02","Duration":"15","nSituations":"1"}]'; // DOES NOT WORK
$matches = '[{"Start":"08:00:00","Duration":"15","nSituations":"1"}]'; // DOES NOT WORK
$matches = '[{"Start":"08:00:00","Duration":"15","nSituations":1}]'; // DOES NOT WORK (nSituations back as INT)
$matches = '[{"Start":"2015-02-02 08:00:00"}]'; // WORKS

I can’t see any pattern. Does anyone know what is going on here? There’s this older post, but it does not quite help me, I don’t think.

Community
  • 1
  • 1
gondolfier
  • 221
  • 1
  • 3
  • 11
  • You need to see where the issue is - monitor the http requests with something like wireshark, then you can see if the issue is the server not responding, or the app failing to deal with the response. – Steve Feb 01 '15 at 22:33
  • Hi Steve, thanks for the input. I don't know about wireshark but I could check it out. When I call the php file from the browser it works fine with all strings. Can the fact that it's being called via AJAX make the php file to fail? – gondolfier Feb 01 '15 at 22:53
  • No, probably not, unless you are sending some data for php to process - if you are just echoing a string, then chances are the server is always sending a responce, and the client is failing to process it in certain instances. I am not familiar with unity so do not know what debugging options are available, but you need to walk through the javascript that performs the ajax and see where it fails – Steve Feb 01 '15 at 22:59
  • No, I'm not sending any data. Just echoing a string (in my debugging mode). And it still fails, so the problem should be at the receiving end. I'll edit the question to make this clear. Thanks for the help – gondolfier Feb 01 '15 at 23:16
  • Please sent unity3d code too. Maybe you forgot calling [StartCoroutine](http://docs.unity3d.com/ScriptReference/MonoBehaviour.StartCoroutine.html) – Barış Çırıka Feb 02 '15 at 14:49

0 Answers0