Hi folks,
I'm looking for advice on how to best run some bash and php scripts together, as seamlessly as possible. I had originally intended to write all these as PHP functions, but discovered bash was more efficient for part of the total process I wanted.

I have 1 bash script that runs in this manner:

run script 1
	(error checking in script 1)
     if fails, write to log; 
else 
run script 2
	(error checking in script 2)
     if fails, write to log
done

if log is generated, mail it as an attachment

I then have 2 PHP files set up in the following way:

script 1
	calls function1.php (does error checking, write to log)
	if fails, call error() function (mails generated log as attachment)
else
	calls function2.php (does error checking, writes to log)
	if fails, call error() function (mails generated log as attachment)

The bash scripts need to run successfully before the PHP scripts run. Would it be best to call the PHP script from my main bash script, or call bash scripts from my main PHP script? Either way, I need to check that the bash script runs before executing the other.

Thanks,
Eve

    My hunch (with no empirical evidence to support it) is that it would save a bit of processing time to have the 2nd bash script call the PHP script upon success, since you then would only invoke the PHP parser/compiler if you actually needed it.

      Thanks, I'll give this a shot. I'll need it to run anyway, as it's part of the total process.

      I guess my other question would be, since each has its own error checking (one in bash, one in PHP), would I be better off simply using what's written in each language, or doing all the error checking in just one way?

      I suppose this is more a matter of what constitutes good coding style.

        I'd also go along with using bash to call PHP; principal reason being that shell scripts were designed to automate system tasks like running programs and moving files about; it's also better at multitasking: with the stdout of one program in a pipeline feeding directly into the stdin of the next, both programs would be run concurrently.

        Unless the checking is particularly expensive in one or the other; I'd use both. In bash, to save time starting up an entire PHP process only to have it encounter the error, and again in PHP so that the PHP program has more chance of being used again for something else.

          Write a Reply...