如何每天从另一台服务器自动加载数据

您好我需要创build一个自动连接到另一个服务器使用PHP库,然后我需要加载数据在MySQL数据库只有第一个file upload一个新的file upload每天。 问题是我如何每天继续上传文件到数据库我几乎在那里

这里是代码:

<?php include 'core/init.php'; include 'includes/overall/header.php'; //connection to linux server $conn = ssh2_connect('xxx.xxx.xx.xxx', 22); $destinationPath = '/path/to/destination/path/'; $localPath = 'C:\path\to\local\path\'; //checks if the connection is successful or not if(ssh2_auth_password($conn, 'username', 'password')){ echo '<script type="text/javascript">alert("Authentication was successful"); </script>'; //javascript pop up when successful }else{ die("Authentication failed"); } if(ssh2_scp_recv($conn, $destinationPath, $localPath)){ echo '<h2>Todays file recieved</h2>'; //if file was recieved from server to local echo todays file recieved, putting the file in localpath }else{ //if the file was not uploaded send an email for radar file too be uploaded $to = 'testemail@yahoo.co.uk'; $subject = 'the subject'; $message = 'hello'; $headers = "From: The Sender Name <senderEmail@yahoo.co.uk>\r\n"; $headers .= "Reply-To: senderEmail@yahoo.coom\r\n"; $headers .= "Content-type: text/html\r\n"; mail($to, $subject, $message, $headers); 

}

 $string = file_get_contents('http://localhost/Prototype/core/edit.txt', 'r');//get contents of file from web used to read the file $myFile = 'C:wampwwwPrototypecoreedit.txt';//file directory $fh = fopen($myFile, 'w') or die("Could not open: " .mysql_error());//open the file fwrite($fh, $string); fclose($fh); $result = mysql_query("LOAD DATA LOCAL INFILE '$myFile'". "INTO TABLE `restartdata` FIELDS TERMINATED BY ',' "); if (!$result) { die("Could not load." . mysql_error()); }else{ echo 'data loaded in the database'; } 

绝对不使用PHP。 绝对没有什么是自制的。 有一个内置的机制。 这就是所谓的复制经过15年以上的尝试和测试,并且正在成千上万的安装中使用。

通过复制,可以将来自一个MySQL数据库服务器(主服务器)的数据复制到一个或多个MySQL数据库服务器(从服务器)。 默认情况下复制是异步的; 从站不需要永久连接以接收来自主站的更新。 根据配置,可以复制数据库中的所有数据库,选定数据库甚至选定的表。

在PHP中这样做意味着整个数据库每天或每小时都会被转储,这意味着在转储过程中站点没有响应。 然后你必须通过HTTP传输整个数据库。

最后但并非最不重要的是你的PHP方法不允许连续存档。 如果您每天进行一次归档,如果系统在上次备份23:50小时后失败,会发生什么情况?