I’m self-taught so bear my ignorance.
I’m writing a scriptie to send emails in batches and its gonna be triggered with cron. If the script outputs nothing, the cron does not send an email. that’s good.
What I’m not clear on is the “output”. Would an echo be considered output? And if I wanted the script to output something specific in the email, what is the mechanism for that?
I keep thinking of functions with the return statement as output, but can’t imagine how this would work for a php scriptie, because I can’t imagine a variable space that’s not in the browser.
Strictly for sake of the example, let’s say you pull out emails from the database and you have them in some sort of an array.
You loop trough the array and you use the mail() function (or phpmailer, it really doesn’t matter).
If sending of mail fails, you can notify yourself somehow that certain emails weren’t sent, such as creating a textual file somewhere describing an error or creating a database entry or trying to send yourself an email (which can fail too so it’s not a good practice).
A shell script can behave exactly like browser one - you don’t have to have any sort of output for the thing to work.
For sending email you generally pass the info to go into the email as INPUT to the mail function.
As for the criteria that you use to determine whether or not to send the mail then that would have nothing to do with any output from the script.
Cron jobs can be set up so that they send you an email if the script outputs anything - that’s when the email to you then contains whatever was produced by an echo or print statement in the script.
The Session id is either stored in a cookie within the browser or is passed between web pages on the end of the UPL in the querystring. Since cron jobs don’t have either you can’t use sessions in cron jobs. What you can do to pass info between executions is to store the info in a file or database on the server and read it back from there in the next execution.
All of the data you want to pass from one script to another or to a new run of the same script must be saved in files or databases on the server.
In the case of scripts that are generating web pages that run in a browser where there may be more than one person accessing the same script at the same time sessions are used to distinguish between the different people running it so that their data saved in files or a database on the server can be readily identified via the session id that is passed on the client either in a cookie or in the querystring.
When you use a session all of the data is written and read on the server for you automatically via the session_start() function (which creates a session object to do the reads at the start and which will do the writes when that object is destroyed at the end of the script).
Then the consensus is “anything” the php script would generate for an html page, such as echo or printing a statement, is also output for cron daemon, yes?
Let me get this sorted out,
PHP has output that, if not caught by another process, is lost. An example would be print and html in a browser,
PHP can write files to the disk drive,
PHP can save to mysql, of course
PHP can write to the “output buffer” which is some allotment of ram space with the server and php’s engine and then retrieve this later, no?
Sessions are on the client machine when using a browser. Is this only with a browser? Can a php script run with cron have a session between executions of the script running every 15 minutes?
PHP.net is rather vague on the subject of output not for the browser or mysql.