php exec我在哪个目录?

How to know in which directory you are now when executing this:

exec("php somescript.php"); - how to know where I am now, to know where I need to go to execute my script?

You can either use the pwd command or PHP's built-in function getcwd() to get the working directory. The latter is recommended.

However, if you know the absolute path of your PHP script, you should just specify that and don't care about what directory you're currently in.

exec("php /path/to/somescript.php");

string getcwd ( void ):

Returns the current working directory on success, or FALSE on failure.