Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot set PHP temporary directory in CLI (sys_temp_dir) #828

Closed
adamziel opened this issue Dec 1, 2023 · 1 comment · Fixed by #953
Closed

Cannot set PHP temporary directory in CLI (sys_temp_dir) #828

adamziel opened this issue Dec 1, 2023 · 1 comment · Fixed by #953
Labels
[Package][@php-wasm] CLI [Type] Bug An existing feature does not function as intended

Comments

@adamziel
Copy link
Collaborator

adamziel commented Dec 1, 2023

php-wasm-cli cannot create temporary files because it doesn't seem to use any custom sys_temp_dir value.

This program:

<?php
	var_dump(ini_get("sys_temp_dir"));
	ini_set("sys_temp_dir", "/tmp");
	var_dump(ini_get("sys_temp_dir"));
	var_dump(sys_get_temp_dir());
	var_dump(tmpfile());

Gives this output:

string(0) ""
string(0) ""
string(48) "/var/folders/sb/cywb762129g3f0jzq1_p2q5h0000gp/T"
bool(false)

When ran as:

nx run php-wasm-cli:start ./test.php

I tried feeding sys_temp_dir through php.ini and php.setPhpIniEntry without any luck.

Done is

Programs ran via php-wasm-cli can create temporary files and directories in the temporary dir defined by sys_temp_dir

@adamziel adamziel added [Type] Bug An existing feature does not function as intended [Package][@php-wasm] CLI labels Dec 1, 2023
@adamziel adamziel mentioned this issue Dec 1, 2023
@adamziel adamziel changed the title Invalid sys_temp_dir in php-wasm-cli Cannot set PHP temporary directory in CLI (sys_temp_dir) Dec 1, 2023
@adamziel
Copy link
Collaborator Author

adamziel commented Dec 27, 2023

Setting the TMPDIR env variable helped:

$ TMPDIR=`pwd`/tmp PHP=8.2 nx start php-wasm-cli  ./test.php
string(0) ""
string(0) ""
string(58) "/Users/cloudnik/www/core/plugins/playground/tmp"
resource(4) of type (stream)

adamziel added a commit that referenced this issue Jan 17, 2024
## The problem

* `npm` scripts set the TMPDIR env variable
* PHP accepts a TMPDIR env variable and expects it to
be a writable directory within the PHP filesystem.

These two clash and prevent PHP from creating temporary
files and directories so this PR prevents exposing the npm-set `TMPDIR` env variable to PHP.

Closes #828

## Testing instructions

Run the following PHP script with and without this PR:

```php
<?php
	var_dump(sys_get_temp_dir());
	var_dump(tmpfile());
```

Run it as follows:

```
nx reset; PHP=8.2 nx start php-wasm-cli
```

Without this PR, it should print something like this:

```
string(48) "/var/folders/sb/cywb762129g3f0jzq1_p2q5h0000gp/T"
bool(false)
```

With this PR, it should print this:

```
string(4) "/tmp"
resource(4) of type (stream)
```
adamziel added a commit that referenced this issue Jan 17, 2024
* `npm` scripts set the TMPDIR env variable
* PHP accepts a TMPDIR env variable and expects it to be a writable
directory within the PHP filesystem.

These two clash and prevent PHP from creating temporary files and
directories so this PR prevents exposing the npm-set `TMPDIR` env
variable to PHP.

Closes #828

## Testing instructions

Run the following PHP script with and without this PR:

```php
<?php
	var_dump(sys_get_temp_dir());
	var_dump(tmpfile());
```

Run it as follows:

```
nx reset; PHP=8.2 nx start php-wasm-cli
```

Without this PR, it should print something like this:

```
string(48) "/var/folders/sb/cywb762129g3f0jzq1_p2q5h0000gp/T"
bool(false)
```

With this PR, it should print this:

```
string(4) "/tmp"
resource(4) of type (stream)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package][@php-wasm] CLI [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant