General Q: how to run/schedule a php script from cron jobs maybe via bash from shell?

Status quo is, within a web application, which is coded completely in php (not by me, I dont know php), I have to fill out several fields, and execute it manually by clicking the "go" button in my browser, several times a day.

Thats because:
The script itself pulls data (textfiles) from a folder, and works them off one by one. As PHP has limitations regarding execution timings (server restrictions aswell), it can be, that not all the data (textfiles) are executed, so the php-script has to be restartet again and again, where it continues, where it has stopped its work.

My idea is, to run that php-script somehow, as a cron job where I have to set the maximum data to be executet, (maybe 50 textfiles), and run the script every 5 minutes, with these parameters.

What would be the wisest approach for this task? Is it generally possible?

edit:
I could find out, that I can run php from shell and also am able to give it the parameters it need, for example like this:

php functions.php -r '$_GET[parameterX]="whattever";'

Is there something like a "debug mode" which I could switch on, in order to see what parameters go to what variables or what functions are called and so on, when I call the script from the web interface.

$dbg=1; does not seem to help me in any way....

Preferebally debug information should be written into a text file.

edit 2:
So far, I am digging through the code of the php-file corrosponding to the dialog screen, and collecting & writing down the variables of the settings I need to make.

Someone please stop me, if I am on the wrong way and wasting my time.. :sunglasses:

Well, there are two ways. One, you can invoke the php file/script using "php <filename>" . I believe you can specify command-line arguments, but to specify query parameters, just set the QUERY_STRING environment variable, ala the CGI specification.

QUERY_STRING='parm1=val1&parm2=val2' php file.php 

The other thing you can do, is direct "curl" to request the page which is requested when you normally hit GO. Do a man on curl to see how you can, for instance, create a web query.

Thanx alot otheus, for these golden hints.

My first try will be that curl thing... Too bad I am a total noob with php.

From what I tried, this one seems to

  • log me in propperly, and
  • saves a cookies.txt, as a textfile, which seems to be valid and
  • loads the exact page, where the go button is, and where all the parameters have to filled into the form.

I call it with: php curl.php > test.html
and If I open the test.html with my browser, I see the exact copy of the page

But now the next step would be, clicking to the go button somehow, and of course "filling out the form" befor clicking go.

There I am stuck now... I have no idea how to do that...

<?php
$username="test";
$password="test";
$cookie="cookies.txt";
$url="http://192.168.0.234/";
$postdata = "log=". $username ."&pwd=". $password ."&subm-cia=Log%20In&redir_to=". $url ."cia/edit.php?page=CIA.php";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url . "login-cia.php");
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_REFERER, $url . "login-cia.php");
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);
curl_close($ch);
echo $result;

exit;
?>

edit:
as far as I could research so far there are $_get and $_post ways to set variables. In my case $_get would be easy, as I could set the variables via the url. I now have to figure out how I can handle this if I have $_post is used here.

Ok, I have extended the script so now it looks like this.

As told above, logging in, and loading the correct dialog screen works well. Now I have to fill the form and send its content to the server via POST Variables.

I could research, that something like this should work, but I seem to have errors in it, as I have only the same result as above. I still get the formular loaded in the html file, but expect to see something else. What I dont understand is how does the script press the Submit "go" button? Testwise I fill the variable:searchterm=anysearchword

<?php
$username="test";
$password="test";
$cookie="cookies.txt";
$url="http://192.168.0.234/";
$postdata = "log=". $username ."&pwd=". $password ."&subm-cia=Log%20In&redir_to=". $url ."cia/edit.php?page=CIA.php";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url . "login-cia.php");
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_REFERER, $url . "login-cia.php");
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);

function curlStart($domain, $var = false){
$fp = curl_init($domain);
curl_setopt($fp,CURLOPT_TIMEOUT,60);
curl_setopt($fp,CURLOPT_FAILONERROR,0);
curl_setopt($fp,CURLOPT_RETURNTRANSFER,1);

if\($var != false\) \{
    curl\_setopt\($fp,CURLOPT_POST,1\);
    curl_setopt \($fp, CURLOPT_POSTFIELDS, $var\); 
\}

curl_exec\($fp\);

if\(curl_errno\($fp\) != 0\) \{
    $send = FALSE;
\} else \{
    $send = TRUE;
\}

curl_close\($fp\);

return $send;

}

$formURL = 'http://192.168.0.234/cia/edit.php?page=CIA.php';
$var = 'searchterm=anysearchword';

for($x=0;$x<1;$x++) {
$send = curlStart($formURL,$var);
}

exit;
?>