PHP cron重新加载灾难

PHP cron重新加载灾难,php,curl,cron,Php,Curl,Cron,我制作了一个脚本,在一个第三方网站的几个页面上迭代寻找数据,我需要每天在crontable上运行一次。按照我目前编写的方式,在浏览器上测试它的功能,如果找不到它要查找的数据,脚本将使用javascript重新加载到下一页。所以这在cron中不起作用。简单地循环函数的问题是我不能多次运行此函数:http_get()定义为 function http_get($target, $ref) { return http($target, $ref, $method="GET", $dat

我制作了一个脚本,在一个第三方网站的几个页面上迭代寻找数据,我需要每天在crontable上运行一次。按照我目前编写的方式,在浏览器上测试它的功能,如果找不到它要查找的数据,脚本将使用javascript重新加载到下一页。所以这在cron中不起作用。简单地循环函数的问题是我不能多次运行此函数:http_get()定义为

function http_get($target, $ref)
    {
    return http($target, $ref, $method="GET", $data_array="", EXCL_HEAD);
    }

function http($target, $ref, $method, $data_array, $incl_head)
    {
    # Initialize PHP/CURL handle
    $ch = curl_init();

    # Prcess data, if presented
    if(is_array($data_array))
        {
        # Convert data array into a query string (ie animal=dog&sport=baseball)
        foreach ($data_array as $key => $value) 
            {
            if(strlen(trim($value))>0)
                $temp_string[] = $key . "=" . urlencode($value);
            else
                $temp_string[] = $key;
            }
        $query_string = join('&', $temp_string);
        }

    # HEAD method configuration
    if($method == HEAD)
        {
        curl_setopt($ch, CURLOPT_HEADER, TRUE);                // No http head
        curl_setopt($ch, CURLOPT_NOBODY, TRUE);                // Return body
        }
    else
        {
        # GET method configuration
        if($method == GET)
            {
            if(isset($query_string))
                $target = $target . "?" . $query_string;
            curl_setopt ($ch, CURLOPT_HTTPGET, TRUE); 
            curl_setopt ($ch, CURLOPT_POST, FALSE); 
            }
        # POST method configuration
        if($method == POST)
            {
            if(isset($query_string))
                curl_setopt ($ch, CURLOPT_POSTFIELDS, $query_string);
            curl_setopt ($ch, CURLOPT_POST, TRUE); 
            curl_setopt ($ch, CURLOPT_HTTPGET, FALSE); 
            }
        curl_setopt($ch, CURLOPT_HEADER, $incl_head);   // Include head as needed
        curl_setopt($ch, CURLOPT_NOBODY, FALSE);        // Return body
        }

    curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIE_FILE);   // Cookie management.
    curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIE_FILE);
    curl_setopt($ch, CURLOPT_TIMEOUT, CURL_TIMEOUT);    // Timeout
    curl_setopt($ch, CURLOPT_USERAGENT, WEBBOT_NAME);   // Webbot name
    curl_setopt($ch, CURLOPT_URL, $target);             // Target site
    curl_setopt($ch, CURLOPT_REFERER, $ref);            // Referer value
    curl_setopt($ch, CURLOPT_VERBOSE, FALSE);           // Minimize logs
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);    // No certificate
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);     // Follow redirects
    curl_setopt($ch, CURLOPT_MAXREDIRS, 4);             // Limit redirections to four
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);     // Return in string

    $return_array['FILE']   = curl_exec($ch); 
    # Create return array
    $return_array['STATUS'] = curl_getinfo($ch);
    $return_array['ERROR']  = curl_error($ch);

    # Close PHP/CURL handle
    curl_close($ch);

    # Return results
    return $return_array;
    }

我有什么办法可以解决这个问题吗?谢谢

我不确定您的问题是什么-您可以让循环包含调用函数的代码,而不是函数本身


或者,使用来测试您是否已经定义了函数。

Hmm,也许我的问题是我试图从函数内部重新实例化一个函数?就像函数x(){if($y=0){x();}}}一样,尽管我的问题很糟糕,但你帮了我,我让它工作了!谢谢