Skip to content

Conversation

@adamziel
Copy link
Collaborator

@adamziel adamziel commented 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
	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)

## 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 adamziel added [Type] Bug An existing feature does not function as intended [Package][@php-wasm] CLI [Feature] PHP.wasm labels Jan 17, 2024
@adamziel adamziel merged commit be9874e into trunk Jan 17, 2024
@adamziel adamziel deleted the adamziel-patch-1 branch January 17, 2024 16:27
adamziel added a commit that referenced this pull request Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] PHP.wasm [Package][@php-wasm] CLI [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot set PHP temporary directory in CLI (sys_temp_dir)

2 participants