1

I have 2 php scripts that start.php runs s_supervisor.php in background so that browser becomes free and not waiting for s_supervisor.php loops be done. It was working awsome in "windows 10 XAMPP" but after afew months I ran the same codes again but the start.php does not trigger (call or run) the s_supervisor.php despite I didn't even touh any character of codes! Whats the probable problem? the codes that I have are below.

<?php # start.php
if(isset($_POST['start_supervisor'])) {     
        $myfile = fopen("spvc.ini", "w");       
        fclose($myfile);
        exec("php -f s_supervisor.php >/dev/null 2>&1 &");
    }       
?>              
<?php # s_supervisor.php
while(file_exists("spvc.ini")) {
      if (file_exists("/error.log")) {
          array_map( 'unlink', array_filter((array) glob("output_dir/*") ) );
      }
}
?>
  • Probably file permissions or file locations changed. Have you verified those? Use conditionals on `if`s to see what is happening – user3783243 Jul 11 '23 at 17:23
  • Relative/Absolute Path, Php binary, perms, all of these are ok ? – Marcelo Guedes Jul 11 '23 at 17:37
  • Where does **$output_dir** come from? – Pippo Jul 11 '23 at 19:11
  • 3
    Redirect the output to a file instead of `/dev/null` so you can see why it's failing. – Barmar Jul 11 '23 at 19:23
  • the code of start.php looks modified, this is likely a sign you're not asking about the real picture. isolate first before asking the question and have a clear test-subject, compare [mre]. Additionally you don't need to have the closing `?>` tag, it is often better to not use it. Even when you don't do in your own code, please keep it out from your example when posting it on Stackoverflow. More info: [Why would one omit the close tag?](https://stackoverflow.com/q/4410704/367456) – hakre Jul 11 '23 at 20:33
  • Additionally your code does not have any error handling **despite** you write in your question you're seeing an error picture. Add error handling so that it becomes more clear what **not working** actually means. Otherwise everyone has to guess, which is likely the reason you're seeing many comments. And which PHP version do you have in use? Please add all clarifications to your question by [edit]ing it. – hakre Jul 11 '23 at 20:36
  • @user3783243 locations are not changed, never. But what do you mean with permissions? which permissions do you suggest to check? I thought alot and GUESS I hade some background updates in my system and that made some changes (that can be some permissions). – Saeed Eisakhani Jul 12 '23 at 08:13
  • 1
    @MarceloGuedes as I mentioned, everything was working perect and I did not touch any charachter in my codes and locations. I dont know what permissions I must check. – Saeed Eisakhani Jul 12 '23 at 08:16
  • @Pippo ```$output_dir``` was a mistake, correction of that is ```glob("output_dir/*")``` – Saeed Eisakhani Jul 12 '23 at 08:18
  • @Barmar "s_supervisor.php" runs perect by itself when I browse " http://localhost/s_supervisor.php " in my browser. And also takes the browser in hang while running loops. It means that s_supervisor.php in OK and the problem is just with ```exec("php -f s_supervisor.php >/dev/null 2>&1 &");``` – Saeed Eisakhani Jul 12 '23 at 08:23
  • @hakre No start.php in not modified I just removed HTML (client side) parts to make my question simple and understandable. Also I did not mention that I have errors. I dont get any errors to illustrate with picture. – Saeed Eisakhani Jul 12 '23 at 08:27
  • You mentioned this: _"but the start.php does not trigger (call or run)"_. If this is not an error for you, then it must be standard operation. So why are you considering it a problem then if it's standard operation? And take care when comparing against requests in the browser and on the command-line (exec): Normally those are different PHP SAPIs. Only the command works in one, does not mean it works in the other. Take care. – hakre Jul 12 '23 at 08:31
  • @hakre I am sure start.php does not trigger the "s_supervisor.php" because I have error.log file, and according to "s_supervisor.php" the contents of "output" directory most be cleaned but they are not!!! in an other hand when I run " localhost/s_supervisor.php " the "output" directory be cleaned (actuall what I want). – Saeed Eisakhani Jul 12 '23 at 08:37
  • Yes, however I didn't question that. What I was commenting about is that you need to find out, where exactly it is going wrong and then why. For me this looks like a configuration issue (if it helps). This can mean that the more interesting parts for your trouble-shooting are not shown in the question but are entirely within the environment you have. Your writing that you have not changed the code is normally a sign that other parts have changed as otherwise the behaviour would not have changed. It is just, that you have not yet identified those changes. – hakre Jul 12 '23 at 08:51
  • @hakre do you know what permissions do I need to check for? some comments reffer to permissions! thanks you – Saeed Eisakhani Jul 12 '23 at 09:49
  • you're searching, instead of looking. the later works better. add php error logging to the `php` command specifically and then check the error log. it will show you if there is a permission issue or not. additionally you can use the error_log() function to add diagnostics (if you don't want to use assert()) with php file-system functions, e.g. to test for permissions. add the output of the error log to your question. also verify the working directory of the process, this can be a common issue, you don't have permissions if the file or directory does not exists. – hakre Jul 12 '23 at 09:58
  • hi @SaeedEisakhani, the perms are to the php binary. Some events can change the default behavior of php binary, then you need check if "php user"(that run this script) have perms on /bin/php or /usr/bin/php or another path. In the shell, you can get the default location: "# which php", then you can test now if the php user can call the binary file. – Marcelo Guedes Jul 12 '23 at 15:34

0 Answers0