PHP script run in background by CGI - Cron Job and Mail Processing

Login or register to post comments
16 replies [Last post]
Offline
Joined: 04/09/2009

Hi,

I have a script that runs as Cron job and another that runs in response to an incoming mail. For both of them I am doing some db selection but can't use the db model of qcubed as it does not allow including the files. For the incoming mail script it gives following error in response to the email:

Parse error: syntax error, unexpected T_CLASS in /home/franc38/public_html/outils/includes/configuration/prepend.inc.php on line 40

Is there any way I can use the db model classes generated by the qcubed in these scripts?

Please help.

Thanks a ton!!!

Offline
Joined: 03/31/2008

Since QCubed is a web framework, you may need to have the php file executed via Apache, but other than that, it should work fine.

I have the following set as a cron task without any issues:

/usr/bin/wget -o /dev/null -O /dev/null --no-check-certificate http<s>://<domain>/cron.php

Offline
Joined: 04/09/2009

Thank you VexedPanda. But I am really not worried about cronjob right now. Can anything be done for inbound email processing?

Offline
Joined: 03/31/2008

What's triggering your PHP script that's dealing with the e-mails? If you trigger it via a web request, same as the cron job, it should work as well..?

alex94040's picture
Offline
Joined: 11/06/2008

You should be able to include QCubed into your regularly scheduled Daemon. I have my mail sending configured exactly the same way.

Tips: in your daemon, use curl or wget, don't use the php interpreter directly.

Also: what's around line 40 on that file that's giving the error?

Offline
Joined: 04/09/2009

I am using a forwarding method on the email and forward it to piped script. My script starts with CGI command to run php -> #!/usr/bin/php. This is all best described at: http://evolt.org/incoming_mail_and_php.

Alex, line 40 is the abstract class declaration. I have not modified prepend.inc.php.

Thanks for all the help.

alex94040's picture
Offline
Joined: 11/06/2008

Don't use the Cgi script like that. Have your script get the webpage with the daemon using wget or curl, and your problems will go away.

Offline
Joined: 04/09/2009

Thats a great idea. Thank you both for helping!!!

Offline
Joined: 04/09/2009

Alex,

I am stuck here. Even if I have a webpage to call through CURL, I would require to POST the email that I received to the page to be able to process it. I have no idea how to POST to the internal page generated by qcubed.

Please help me with it.

Thank you.

alex94040's picture
Offline
Joined: 11/06/2008

Google "how to make a POST request with curl" and find:

http://stackoverflow.com/questions/84619/how-do-i-make-a-post-request-wi....

Offline
Joined: 04/09/2009

Alex,

I have used cURL before. But I don't know how to configure my web page developed with qcubed to be able to accept data from cURL command. As, I want to forward the whole email to that webpage and then to the further processing.

Thank you.

alex94040's picture
Offline
Joined: 11/06/2008

If you send in a POST, you can just look at the data in $_POST. Or, your PHP script can just read a file that your shell script writes.

Offline
Joined: 03/31/2008

How does the PHP file currently get access to the e-mail? I don't see why that mechanism would need to change..?

Offline
Joined: 04/09/2009

It reads from stdin:

<?php
$fd
= fopen("php://stdin", "r");
$email = "";
while (!
feof($fd)) {
   
$email .= fread($fd, 1024);
}
fclose($fd);
?>

Do you think I can just read the mail like this, even when I POST to this script from the forwarded script. Currently this is the call sequence:

Mail--[FWD]-->script1_To_process_mail

So can I simply change it to:

Mail--[FWD]-->script0_To_Processing_Script--[POST]-->script1_To_process_mail

to be able to use QCubed in script1_To_process_mail.

alex94040's picture
Offline
Joined: 11/06/2008

If you POST to the script, you obviously can't read the data from stdin - because it's not there. If you POST to it, the data can be read from the $_POST['varname'] variable.