try:

exec("nohup php /mnt/notif/external.php 4 5 abc 7 xyz");

    Ok ... this seemed to work fine from the command line calling the main script and the called script (with exec()) but when I place it in a cron job, it seems to crap out. Could it be the message about nohup redirecting stderr to stdout? Even though the notification was generated from the command line, everything worked fine.

    Any insight is greatly appreciated!

    Bill

      What is the difference between exec() and shell_exec()?

        The differences are the arguments they accept and what they return. See [man]shell_exec/man and exec() for specifics. (I know, RTFM type replies suck, but it's either that or me just copy-and-pasting what the manual says here.)

          I read the manual and the only difference IS what they return. In my situation as described above, neither seem to have and advantage or disadvantage and also it seems that they would work identical (in the above scenario). I am just looking for some rhyme or reason that it worked at the command line and not as a cron job.

          When I look at 'top' I only have 2 php instances at any time running. It seems to be waiting on the response. I assume the two instances are the script the cron job calls and the exec() script. Being a novice I probably am missing something but it seems that if the main script is not waiting on the exec()'d script to complete before it continues, there should be multiple exec()'d scripts showing in top. That is provided the exec()'d scripts have not completed .... which they shouldn't with seconds of each top update.

          Thanks ... Bill

            shouldn't need nohup for a cron job but you may want to specify the path for php. are you running exec in a cronjob? im a little confused now.

              No, I am running exec from a script that is run by the cron. The script kicked off and is running but, at most, there are only two php processes at one time. The main script appears to be waiting for the return of exec. I call it from the main script (the one started by cron) by:

              $_dummy = exec("nohup php /mnt/notifs/utils/script_run_by_cron.php '$current_list' '$key' '$secret' '$id' '$temporary_table_name' '$user_limit'");
              

              The variable all contain valid values and transferred fine run from the command line. I am wondering if maybe even at the command line it was waiting on the exec command to complete and I simply didn't notice it.

              Sorry for any confusion! I have been working on this for many hours with no resolve. Could it be that I assign the result of the exec() function to a variable? Could that be telling it to wait? The only thing I haven't tried is exec(command_string) on a line by itself without the $_dummy variable assignment.

              Thanks,

              Bill

                A test:

                cron script:

                for ($i = 1; $i <= 10; $i++) {
                exec("test.php $i");
                }

                test.php

                sleep(60);

                then use: ps ax | grep 'php'

                to see it there are the 10 scripts

                  Didn't even have 2 do that ... the script that I set in motion over 4 hours ago is still running ... one exec at a time. When I ps I get the main cron script and only one of the execs .... ran it several times and there are only two at a time.

                    Ran your script and there were always 2 scripts running ... the calling (test1) and the exec()'d (test). After 60 seconds, the test would have the parameter of 2, 60 more then 3 ... not all at once.

                    The server is an amazon ec2 cloud. I have an xlarge and large server. Any idea with that?

                    Thx!

                      talk to your hosts support, it sounds like an issue at their end

                        I can control the configuration. Any idea where the problem may be. I can install software .. just as it were my server.

                          I can install software/change configuration. Any idea what may be the issue?

                            oops ... sorry .. .didnt mean to post twice ... i failed to look at the second page.

                              Write a Reply...