kevinmel2000 / phpdesktop

Automatically exported from code.google.com/p/phpdesktop
1 stars 0 forks source link

Add an example of setting temp dir on Win8 to solve tmp dir problems on this OS. #39

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. sys_get_temp_dir(); returns "C:\windows"
2. This folder is not writeable by php
3. This causes extensions to malfunction when they need to write temporary files

I would expect the temp folder to be C:\windows\temp or something that I can 
write to.

I am using php_desktop_msie_v10 on Windows 8.

First, I'd like to say that I really like this runtime environment. It's a 
great idea and I've found it very easy to work with. I'm running into this 
problem when trying to use ImageMagick, but I can see it being a problem with 
other extensions as well. I can't find a php.ini directive to change the temp 
folder, so I'm wondering if there's some other way to do it?

Original issue reported on code.google.com by johnrfai...@gmail.com on 3 Jul 2013 at 9:02

GoogleCodeExporter commented 9 years ago
This is a problem in PHP itself, it seems that the temp directory is
detected incorrectly. See Issue 23 for a similar problem, the solution
for session files temp dir or upload temp dir is to set the 
"session.save_path" or "upload_tmp_dir" php.ini options by using 
ini_set() or by editing php.ini in the php/ folder.

But this will probably won't work in other cases that need a general
temp directory. There is an another php option "sys_temp_dir" that
you can try set, the php documentation says that it is available only
since php 5.5.0, I've found the php bug 60524 that solves this issue
and provides patches for other php versions:

https://bugs.php.net/bug.php?id=60524

Try one of these, it probably won't work in php 5.4, but it won't hurt
to test it:

1. ini_set("sys_temp_dir", "C:/Windows/Temp");
2. Edit php.ini and add: sys_temp_dir=C:/Windows/Temp

The php documentation says that the "sys_temp_dir" option is PHP_INI_SYSTEM,
meaning it can be set only through php.ini,

Let me know if setting "sys_temp_dir" works in php 5.4, if not then we will
have to provide our own custom build of PHP 5.4 to solve this issue.

If you are fine using php 5.5 then you can fix it yourself by updating the
binaries, the downside of using php 5.5 is that it doesn't support Windows XP
anymore.

Original comment by czarek.t...@gmail.com on 4 Jul 2013 at 6:27

GoogleCodeExporter commented 9 years ago
Thanks for responding so quickly. I had the session and file upload problem 
myself and put the "session.save_path" and "upload_tmp_dir," directives in 
php.ini already. I found that thread on php.net too, so I had the 
"sys_temp_dir," directive as well. It doesn't seem to do anything. I tried 
putenv too.

At any rate, I went to window.php.net and got the VC11 x86 Non Thread Safe 
release of php 5.5. I installed this in the program folder for PHP Desktop. The 
way I did this was I just copied the files from the php folder in my downloads 
to the php folder of PHP Desktop. I also copied the ext files (the same files 
that were with PHP Desktop).

Now, when I launch PHP Desktop, I get an error "MSVCR110.dll is missing from 
your computer." I Googled this and found that it meant I didn't have the right 
VC++ Redistributable. I got the right one from Microsoft:

http://www.microsoft.com/en-us/download/details.aspx?id=30679

I got this installed; but the error is still there, so I'm not able to test 
whether php 5.5 will solve the problem.

Original comment by johnrfai...@gmail.com on 5 Jul 2013 at 2:02

GoogleCodeExporter commented 9 years ago
On the Visual C++ Redistributable page you pasted link to I see a few files:

VSU3\vcredist_arm.exe 1.4 MB
VSU3\vcredist_x64.exe 6.9 MB
VSU3\vcredist_x86.exe 6.2 MB

Which one did you install? You are supposed to install vcredist_x86.exe,
as you have downloaded php 5.5 x86.

Original comment by czarek.t...@gmail.com on 5 Jul 2013 at 2:35

GoogleCodeExporter commented 9 years ago
Ok, thanks for your help. I had the x64 version installed. I got PHP 5.5 to 
work and it changed the temp folder just fine with that php.ini directive! 
Unfortunately, the extension that I'm trying to use (imagick) doesn't work with 
php 5.5 yet.

So, to get this to work, do I just need to apply that php patch and then build 
5.4 from source?

Original comment by johnrfai...@gmail.com on 5 Jul 2013 at 6:37

GoogleCodeExporter commented 9 years ago
> So, to get this to work, do I just need to apply that php patch and
> then build 5.4 from source?

Yes, that patch adds support for setting temporary directory, if setting
sys_temp_dir works for you in php 5.5 then this patch will make it work
the same in php 5.4.

Notice that the patch for php 5.4 has the option named "system_temp_dir",
in php 5.5 it is "sys_temp_dir", you can see the commit to php 5.5 here:

https://github.com/php/php-src/commit/475a644bd84c071da04b4272b829a187a2c6d282

Original comment by czarek.t...@gmail.com on 5 Jul 2013 at 6:59

GoogleCodeExporter commented 9 years ago
There might be a simpler solution for php 5.4, try this:

<?php
putenv("TMP=C:/Windows/Temp");
putenv("TEMP=C:/Windows/Temp");
putenv("TMPDIR=C:/Windows/Temp");
?>

It seems that on Windows the TMP and TEMP environment variables are checked,
the TMPDIR is probably only for Linux/Mac.

You could use the auto_prepend_file directive to set it up for all scripts.

For reference: http://stackoverflow.com/a/13254317/623622

Original comment by czarek.t...@gmail.com on 6 Jul 2013 at 5:52

GoogleCodeExporter commented 9 years ago
John, can you confirm that in php 5.5 the temp directory is also "C:\Windows"?

I've found the php bug #64410 that is about the issue we're having:

https://bugs.php.net/bug.php?id=64410

Original comment by czarek.t...@gmail.com on 6 Jul 2013 at 2:08

GoogleCodeExporter commented 9 years ago
All those putenvs work in 5.4 and 5.5. They change the temp directory. In 5.5, 
before putting those in, the temp dir was c:\windows.

I actually found that this didn't solve my problem with ImageMagick. IM is 
trying to use some other temp dir. I gave up on it for now, but the 
c:\windows\temp should be fixed with the solution you gave above.

Original comment by johnrfai...@gmail.com on 8 Jul 2013 at 6:32

GoogleCodeExporter commented 9 years ago
What directory is IM trying to use even after using putenv() fix? This
would mean that IM is trying to detect the temporary directory on its own,
but this is very unlikely IMO. Or it is being detected and kept when the
extension is being imported, this seems odd, but in this case the php.ini 
"sys_temp_dir" should fix this.

Try this for the magick problem:

<?php
putenv("MAGICK_TEMPORARY_PATH=C:/Windows/Temp");
putenv("MAGICK_TMPDIR=C:/Windows/Temp");
putenv("MAGICK_TMP=C:/Windows/Temp");
putenv("MAGICK_TEMP=C:/Windows/Temp");
putenv("IMAGICK_TEMPORARY_PATH=C:/Windows/Temp");
putenv("IMAGICK_TMPDIR=C:/Windows/Temp");
putenv("IMAGICK_TMP=C:/Windows/Temp");
putenv("IMAGICK_TEMP=C:/Windows/Temp");
?>

Original comment by czarek.t...@gmail.com on 8 Jul 2013 at 7:04

GoogleCodeExporter commented 9 years ago
I've checked sources of the imagick extension:

http://pecl.php.net/package/imagick

I haven't found anywhere in the sources anything related to the temp directory,
it seems that they are not using any temp directory, so I'm confused right now.

Original comment by czarek.t...@gmail.com on 8 Jul 2013 at 7:25

GoogleCodeExporter commented 9 years ago
There was a response in bug 64410 that states this is an environment issue
in Windows 8, probably a TMP/TEMP environmental variable is missing, it
probably affects other applications as well. The fix for php 5.4 is to use
putenv(), for php 5.5+ additionally sys_temp_dir is usable.

Original comment by czarek.t...@gmail.com on 9 Jul 2013 at 6:19

GoogleCodeExporter commented 9 years ago
Thanks for your help. ImageMagick does use a different temp dir from what I've 
read in the documentation. I think it uses the appdata temp folder. I tried the 
MAGICK_TEMPORARY_PATH variable, but not the others. After working with this 
issue for a while, I don't think it's a problem with PHP Desktop, although I 
think it's important to set the temp dir at any rate. I'm running the 
ImageMagick processes on my server for now.

Original comment by jfairf...@kmdg.com on 9 Jul 2013 at 6:41

GoogleCodeExporter commented 9 years ago
A php example script will be added to the php desktop binaries with an
exaplanation that PHP temp environment variables should be set on this OS.

Original comment by czarek.t...@gmail.com on 21 Jul 2013 at 6:38

GoogleCodeExporter commented 9 years ago

Original comment by czarek.t...@gmail.com on 19 Jan 2014 at 7:39

GoogleCodeExporter commented 9 years ago
Issue 41 has been merged into this issue.

Original comment by czarek.t...@gmail.com on 19 Jan 2014 at 7:39

GoogleCodeExporter commented 9 years ago
Issue 23 has been merged into this issue.

Original comment by czarek.t...@gmail.com on 19 Jan 2014 at 11:40

GoogleCodeExporter commented 9 years ago

Original comment by czarek.t...@gmail.com on 21 Jan 2014 at 12:32

GoogleCodeExporter commented 9 years ago
Issue 23 has been merged into this issue.

Original comment by czarek.t...@gmail.com on 22 Jan 2014 at 4:07

GoogleCodeExporter commented 9 years ago
I have investigated the issue again and the problem was that the TMP 
environment variable was not set by the Mongoose webserver. Fixed in revision 
89f4820f0bf1. Added the upload and session examples.

Original comment by czarek.t...@gmail.com on 22 Jan 2014 at 4:07

GoogleCodeExporter commented 9 years ago

Original comment by czarek.t...@gmail.com on 22 Jan 2014 at 4:07

GoogleCodeExporter commented 9 years ago
Issue 41 has been merged into this issue.

Original comment by czarek.t...@gmail.com on 22 Jan 2014 at 4:08

GoogleCodeExporter commented 9 years ago
Fix for the Chrome branch in revision 667c09e8668d.

Original comment by czarek.t...@gmail.com on 22 Jan 2014 at 5:38

GoogleCodeExporter commented 9 years ago
Version 31.3 of PHP Desktop Chrome released.

Version 1.11 of PHP Desktop MSIE released.

Original comment by czarek.t...@gmail.com on 22 Jan 2014 at 9:13