select temporary directory based on env vars

I always apply this patch to use TMP or TMPDIR or TEMP variables to select debug directory (here php can't write to /tmp)

It may also help windows users ?