dongzouqie4220 2016-11-24 11:39
浏览 23

安排任务不起作用

i have one php file and i am using ftp_get() function in it. when i run it from server localhost it's running fine but when i run it from schedule task it's giving error. here's my code.

<?php

$ftp_server = "IP"; 
$conn_id = ftp_connect ($ftp_server) 
or die("Couldn't connect to $ftp_server"); 

$login_result = ftp_login($conn_id, "syslog", "Gms$67"); 
if ((!$conn_id) || (!$login_result)) 
die("FTP Connection Failed"); 
ftp_pasv($conn_id, true);
echo "Start time:".date("d-m-Y h:i:sa")."<br/>";
ftp_sync (".");    // Use "." if you are in the current directory 

echo "<br/>End time:".date("d-m-Y h:i:sa")."<br/>";

ftp_close($conn_id);  

// ftp_sync - Copy directory and file structure 
function ftp_sync ($dir) { 

global $conn_id; 

if ($dir != ".") { 
    if (ftp_chdir($conn_id, $dir) == false) { 
        echo ("Change Dir Failed: $dir<BR>
"); 
        return; 
    } 
    if (!(is_dir($dir))) 
        mkdir($dir); 
    chdir ($dir); 
} 

$contents = ftp_nlist($conn_id, "."); 
foreach ($contents as $file) { 

    if ($file == '.' || $file == '..') 
        continue; 

    if (@ftp_chdir($conn_id, $file)) { 
        ftp_chdir ($conn_id, ".."); 
        ftp_sync ($file); 
    } 
    else
    {

        if(ftp_get($conn_id, "files/syslog.txt", $file, FTP_BINARY))
        {
            $mbody=  nl2br(file_get_contents("files/syslog.txt"));
            //$f = fopen('files/syslog.txt', 'r+');
            //$mbody = fread($f, filesize("files/syslog.txt"));
            //fclose($f);
            $resArray = explode("
",$mbody);
            foreach($resArray as $r) {
               $ArrayResults[] = explode(" ",$r,6);
            }

            /*echo "<pre>";
            print_r($ArrayResults);
            echo "</pre>";*/
            $fields="srdate,srtime,facility,severity,host,message";
            foreach ($ArrayResults as $rowValues) {
             //echo "vip==".$rowValues[0]."--<br/>";
             if($rowValues[0]!="")
             {
             $serarray = explode(".",$rowValues[2]);
             //echo "servi=".$serarray[1]."<br/>";
             $facility=$serarray[0];
             $severity=$serarray[1];
            /*foreach ($rowValues as $key => $rowValue) {
                     $rowValues[$key] = mysql_real_escape_string($rowValues[$key]);
                }*/
                $rowValues1[0] = mysql_real_escape_string($rowValues[0]);
                $rowValues1[1] = mysql_real_escape_string($rowValues[1]);
                $rowValues1[2] = mysql_real_escape_string($facility);
                $rowValues1[3] = mysql_real_escape_string($severity);
                $rowValues1[4] = mysql_real_escape_string($rowValues[3]);
                $rowValues1[5] = mysql_real_escape_string($rowValues[5]);
            $values[] = "('" . implode('\', \'', $rowValues1) . "')";
            unset($serarray);
            }
            }
            include("config.php");
             $query = "INSERT INTO syslogtbl ($fields) VALUES " . implode (', ', $values) . "";
            if(mysql_query($query))
            {
             echo "Successfully Insert to Database.";
            }
            else
            {
             echo "<br/>Error in insert syslog".mysql_error();;
            }
        } 
        else
        {
          echo "Error downloading $server_file.";
        } 
    }   
} 

ftp_chdir ($conn_id, ".."); 
chdir (".."); 

} 

?>

when i run from schedule task it shows not any error but also not anything change in output(it must change). then i run file from batch file and it shows error in command prompt is.

C:\script>C:\wamp\bin\php\php5.5.12\php.exe  C:\wamp\www\syslog\schedule_readtxt.php
Start time:24-11-2016 12:33:41pm<br/>
Warning: ftp_get(files/syslog.txt): failed to open stream: No such file or directory in C:\wamp\www\syslog\schedule_readtxt.php on line 69

Call Stack:
0.0000     250200   1. {main}() C:\wamp\www\syslog\schedule_readtxt.php:0
0.0156     259928   2. ftp_sync() C:\wamp\www\syslog\schedule_readtxt.php:35

0.0156     261832   3. ftp_get() C:\wamp\www\syslog\schedule_readtxt.php:69


Warning: ftp_get(): Error opening files/syslog.txt in C:\wamp\www\syslog\schedul
e_readtxt.php on line 69

Call Stack:
0.0000     250200   1. {main}() C:\wamp\www\syslog\schedule_readtxt.php:0
0.0156     259928   2. ftp_sync() C:\wamp\www\syslog\schedule_readtxt.php:35

0.0156     261832   3. ftp_get() C:\wamp\www\syslog\schedule_readtxt.php:69


Notice: Undefined variable: server_file in C:\wamp\www\syslog\schedule_readtxt.p
hp on line 118

Call Stack:
0.0000     250200   1. {main}() C:\wamp\www\syslog\schedule_readtxt.php:0
0.0156     259928   2. ftp_sync() C:\wamp\www\syslog\schedule_readtxt.php:35


Error downloading .<br/>End time:24-11-2016 12:33:41pm<br/>
C:\script>pause
Press any key to continue . . .

i don't know how to run this script from schedule task. please help me.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 seata使用出现报错,其他服务找不到seata
    • ¥15 怎么实现输入一个要删除的数后删除后显示剩余数再输入再删除显示剩余数(语言-c语言)
    • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
    • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
    • ¥15 Google speech command 数据集获取
    • ¥15 vue3+element-plus页面崩溃
    • ¥15 像这种代码要怎么跑起来?
    • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
    • ¥15 pyqt5tools安装失败
    • ¥15 mmdetection