www.progress not work with .php url

hi, i’m freaking out with whis problem… I have to take the www.progress from a php file, but seems like impossible take the www.progress from an URL with php extension.

this is my test script:

if my url point into a file jpg,html,txt or anything except php there’s no problem, but with php files i obtain just a lot of “0” and “1” when the www request is over. why???
there’s no way to show progress for a package request from php??? really need help

Thanks to all of you guys

Hi there

Couple of questions -

  1. Can you validate that if you hit your PHP url in your browser you are getting back what you expect?
  2. What are you trying to accomplish? Are you attempting to show the progress of downloading a web resource?
  3. When you say you are obtaining "0"s and "1"s - what do you mean specifically? Are you saying that your Debug.Log output is showing 0s or 1s or the actual response contained in the www object is something like “01010101” ?
  4. It’s unclear why you are calling yield return on both www.progress and www in addition to having an isDone loop. Calling yield return www will actually wait until the content has downloaded - however you seem to be tracking this already in your loop, you shouldn’t need both.

If you are trying to show incremental progress in your script, you most likely want to do something like this:

WaitForSeconds sleep = new WaitForSeconds(.2f);
WWW www =new WWW("http://www.mysite.it/script.php");
while(!www.isDone) {
  Debug.Log("progress = "+ www.progress);
  yield return sleep;
}

Just one other thought - you may need to set some headers in your PHP script (like Content-Type) so Unity knows what kind of content it’s interacting with.

PHP generates files on the fly and then streams them to the client.

Sounds to me like the client (unity) isn’t receiving information in the header as to how large the stream will be. So it can’t determine how much percentage the current amount of received data is.

Imagine if I handed you an end of rope, and I didn’t tell you how long it was. Then after feeding you more and more rope for a few minutes I asked you what percentage of the total rope you have in your hand… could you answer me? No… you couldn’t. You only know how much you have, not how much there is in total.

1 Like

first of all, thank you both for your reply : )
@justoon
1 - yep all work fine, my php server-side script works fine and i receive all i’ve asked, the problem is not with MY php script, the problem occour in any case with any file with php extension
2 - In my case i’m waiting for a json package and i need to know the download progress fot that package
3 - sorry i try to be more specific: if i try to obtain the progress for any other file type (jpg, html, txt etc) i obtain this from debug log:
progress = 0
progress = 0.0125021
progress = 0.02578805
progress = 0.04350266
progress = 0.09664649
progress = 0.154219
progress = 0.2073628
progress = 0.2782212
progress = 0.3490796
progress = 0.459796
progress = 0.5616549
progress = 0.6856572
progress = 0.7565156
progress = 0.8096595
progress = 0.9380904
progress = 0.9823769

with ANY php files, my scripts, or just a blank one or with some text inside just for give it a little size to monitoring i obtain this:

progress = 0
progress = 0
progress = 0
progress = 0
progress = 0
progress = 0
progress = 0.
progress = 0
progress = 0
progress = 0
progress = 0
progress = 0
progress = 0
progress = 1

4 - ya sorry it’s cause that is just a part of the script and the part with the progress tracking is inside one condition, else i call just for the second yield, my mistake

can u be more specific about headers? what type of headers unity expect to receive? i’m trying to figuring out why unity being mad with php extension when i ask for monitoring the progress, hope someone of you can show me the way.

@lordofduct
Exactly, so with all the other file is ok but for .php package i need headers in the source file? sorry this is my first attempt with programming in php and maybe i forgotten something like this

Ok i did it some test, you both were right, the problem is in the header content-length.
Now i set it in my php scripts, and now it work fine in editor mode but i’ve problems with android device.
i Tested it on 2 different device with 2 different android version, jelly bean and lollipop, and it works on jelly bean only.
Seems like on lollipop content-length it’s lost, this is the catlog log:

Jelly bean:
I/Unity ( 1728): response_headers = HTTP/1.1 200 OK=STATUS
I/Unity ( 1728): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 65)
I/Unity ( 1728): response_headers = Keep-Alive=CONNECTION
I/Unity ( 1728): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 65)
I/Unity ( 1728): response_headers = 110426=CONTENT-LENGTH
I/Unity ( 1728): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 65)
I/Unity ( 1728): response_headers = text/html=CONTENT-TYPE
I/Unity ( 1728): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 65)

Lollipop:
I/Unity (16471): response_headers = HTTP/1.1 200 OK=STATUS
I/Unity (16471): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 65)
I/Unity (16471): response_headers = Keep-Alive=CONNECTION
I/Unity (16471): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 65)
I/Unity (16471): response_headers = text/html=CONTENT-TYPE
I/Unity (16471): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 65)

On lollipop no Content-lenght is arrived…any idea why???