Haxe php http download to file stream

how to download to file stream without loading all request content in memory?

How do you do it with plain php?