问题描述:

I have a strange issue. Only in an executable php script this error happens, and I have no idea why

Warning: fwrite() expects parameter 1 to be resource, string given

I have following examples:

-rwxr-xr-x 1 root root 87 Sep 10 16:55 test*

-rw-r--r-- 1 root root 33 Sep 10 17:10 test.php

Where the file ./test is:

#!/usr/bin/php -q

<?php

fwrite(STDERR, "test\n");

and the file test.php is (exact same, just missing the shebang):

<?php

fwrite(STDERR, "test\n");

I made some tests on that machine and it's behavior is really strange:

# ./test

<br />

<b>Warning</b>: fwrite() expects parameter 1 to be resource, string given

# php -q test.php

test

# php -r 'fwrite(STDERR, "test\n");'

test

Has anyone an idea why fwrite to STDERR does not work (only) in executable php files?

PHP 5.4.28 (cli) (built: May 19 2014 15:39:12)

网友答案:

The error is gone when I use the shebang #!/usr/local/bin/php. Makes sense, since php was compiled from source.

But I still don't understand why this happens on the other path. I tried to look into phpinfo using the 'wrong' shebang and I still get PHP Version 5.4.28 as version, so there aren't multiple installations.

相关阅读:
Top