简体   繁体   English

加载时运行PHP脚本

[英]Run PHP script on load

I have a PHP script which uses the value of an form input box to submit a twitter search via FileGetContents() , it returns the results on screen and stores them in a MySQL database. 我有一个PHP脚本,它使用表单输入框的值通过FileGetContents()提交Twitter搜索,它在屏幕上返回结果并将其存储在MySQL数据库中。

Here is the form: 形式如下:

<form id="backup" action="backup.php" method="get">
    <div id="formContainer">
        <div class="rowtop">
            <span class="formw">
                <input class="search" type="text" onclick="this.value='';" name="tag" value="<?php echo urldecode($tag); ?>"/>
            </span>
        </div>
                <br>
        <div class="row">
                <br><br>
            <span class="formw">
                <input type="text"  onclick="this.value='';" name="maxpages" value="<?php echo $max_pages; ?>"/>
            </span>
        </div>
        <div class="rowbottom"><span class="label"><input type="submit" value="Backup" /></span></div>
    </div>
</form>

I'd like to have this script running as part of a CRON job, so instead of getting the search value from the input i'd like it to be the same value each time its run. 我想将此脚本作为CRON作业的一部分运行,因此与其希望从输入中获取搜索值,不希望每次运行时它都具有相同的值。

What is the easiest way to achieve this? 最简单的方法是什么?

killer_PL's code would work... you're just setting the values manually at the start of the script.. an alternative would be to navigate to killer_PL的代码将起作用...您只是在脚本开始时手动设置值。另一种方法是导航到

"backup.php?tag=XXX&maxpages=XXX" “backup.php?标签= XXX&MAXPAGES = XXX”

If I understood properly your question I would say you simply need the cron job to call directly the script: 如果我正确理解了您的问题,我会说您只需要cron作业即可直接调用脚本:

backup.php?tag=value_you_set&maxpages=another_value_you_set

In the script you set the values for tag key and maxpages key. 在脚本中,设置tag键和maxpages键的值。 You sadi in your question they don't change. 你对他们的问题没有改变表示怀疑。

Cron jobs are running in CLI environemnt, so you should familiarise yourself with this part of manual: Cron作业在CLI环境中运行,因此您应该熟悉手册的以下部分:

http://php.net/manual/en/features.commandline.php http://php.net/manual/en/features.commandline.php

Set a few fake $_GET varaibles at begin of a script: 在脚本的开头设置一些假的$ _GET变量:

$_GET['tag'] = 'mytag';
$_GET['maxpages'] = 10;
$_GET['Submit'] = 'Backup';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM