PHP Internal Function(s) Missing?


Go to solution Solved by KeithAbbott,

Recommended Posts

I just upgraded from 6.10.3 to 6.11.5, no real issues with the upgrade.  I see that Unraid now has PHP included, which is really nice.  However, I am trying to execute a small PHP script from the Unraid Terminal, using the following command:

 

php -f /mnt/user/sagemedia/pictures/DeleteOrphanedRecordingFiles.php

 

I get the following error:

 

Fatal error: Uncaught Error: Call to undefined function  scandir() in /mnt/user/sagemedia/pictures/DeleteOrphanedRecordingFiles.php:18

 

scandir is a PHP internal/built-in function (since version 5), so I'm not sure what I am doing wrong that Unraid's PHP is not recognizing it.  Any ideas?

Link to comment
28 minutes ago, KeithAbbott said:

I just upgraded from 6.10.3 to 6.11.5, no real issues with the upgrade.  I see that Unraid now has PHP included, which is really nice.  However, I am trying to execute a small PHP script from the Unraid Terminal, using the following command:

 

php -f /mnt/user/sagemedia/pictures/DeleteOrphanedRecordingFiles.php

 

I get the following error:

 

Fatal error: Uncaught Error: Call to undefined function  scandir() in /mnt/user/sagemedia/pictures/DeleteOrphanedRecordingFiles.php:18

 

scandir is a PHP internal/built-in function (since version 5), so I'm not sure what I am doing wrong that Unraid's PHP is not recognizing it.  Any ideas?

root@computenode:~# /mnt/user/appdata/test
array(21) {
  [0]=>
  string(1) "."
  [1]=>
  string(2) ".."
  [2]=>
  string(22) "community.applications"
  [3]=>
  string(6) "emhttp"
  [4]=>
  string(13) "file.activity"
  [5]=>
  string(19) "fix.common.problems"
  [6]=>
  string(9) ".ICE-unix"
  [7]=>
  string(9) "mover.php"
  [8]=>
  string(4) "nics"
  [9]=>
  string(13) "notifications"
  [10]=>
  string(7) "plugins"
  [11]=>
  string(11) "recycle.bin"
  [12]=>
  string(9) "snapshots"
  [13]=>
  string(15) "snapshots_27528"
  [14]=>
  string(15) "start_snapshots"
  [15]=>
  string(18) "unassigned.devices"
  [16]=>
  string(13) "update-helper"
  [17]=>
  string(11) "usb_manager"
  [18]=>
  string(12) "user.scripts"
  [19]=>
  string(9) ".X11-unix"
  [20]=>
  string(23) "zfs.master-session.data"
}
root@computenode:~# cat /mnt/user/appdata/test
#!/usr/bin/php
<?php

 var_dump(scandir("/tmp")) ;
root@computenode:~# 

This works fine for me, try adding #! and <?php to the code. chmod +x and then run the file.

Edited by SimonF
Link to comment
43 minutes ago, KeithAbbott said:

I added #! as the first line, and changed the permissions for the .php file to 777.  I already had <?php in the code.  Still getting exact same error message as before.  Here is the stripped down php script that I am executing:


 

#!/usr/bin/php

<?php

$files2 = scandir('/tmp');

?>

 

Not sure why this does not run for you.

 

root@computenode:~# /mnt/user/appdata/test
array(21) {
  [0]=>
  string(1) "."
  [1]=>
  string(2) ".."
  [2]=>
  string(22) "community.applications"
  [3]=>
  string(6) "emhttp"
  [4]=>
  string(13) "file.activity"
  [5]=>
  string(19) "fix.common.problems"
  [6]=>
  string(9) ".ICE-unix"
  [7]=>
  string(9) "mover.php"
  [8]=>
  string(4) "nics"
  [9]=>
  string(13) "notifications"
  [10]=>
  string(7) "plugins"
  [11]=>
  string(11) "recycle.bin"
  [12]=>
  string(9) "snapshots"
  [13]=>
  string(15) "snapshots_27528"
  [14]=>
  string(15) "start_snapshots"
  [15]=>
  string(18) "unassigned.devices"
  [16]=>
  string(13) "update-helper"
  [17]=>
  string(11) "usb_manager"
  [18]=>
  string(12) "user.scripts"
  [19]=>
  string(9) ".X11-unix"
  [20]=>
  string(23) "zfs.master-session.data"
}
root@computenode:~# cat /mnt/user/appdata/test
#!/usr/bin/php
<?php

$files = scandir('/tmp') ;
var_dump($files) ;
root@computenode:~# 

 

Edited by SimonF
Link to comment
  • Solution

It seems to be working now.  I think I was supplying an invalid directory name to the scandir function, and the error that was being returned was a red herring.  Thanks for your help, SimonF!

 

p.s. Turns out that wasn't the root cause of the problem.  I was pasting in some code snippets, and what looked to be spaces in the code were actually a non-space character.  Once I figured that out and over-typed with actual spaces, everything started working smoothly.  I sure was getting some strange results until I found the actual problem.

Edited by KeithAbbott
  • Like 1
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.