clarke78 Posted February 16, 2007 Share Posted February 16, 2007 Hi, I'm looking for the simplest, yet most efficient way to update a set of php scripts from a remote website / server. I would like to update certain files / tables + rows in the remote database. I currently have created a very simple updater based on fopen to read my specified updates.php which will tell the scripts updater.php which files to re-write from my own files on my site. (for the record I had looked into something called Pipes to directly connect to the server or something... it seemed a little complicated though) My Code so far (which works but I'm sure isnt the simplest / best way) Updater.php (on users website) <?php $id = $_GET["view"]; $conn = mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db('table_name', $conn) or die(mysql_error()); if($id == ""){ // make sure the remote file is successfully opened before doing anything else if ($fp = fopen('http://www.MYURL.net/Updates.txt', 'r')) { $content = ''; // keep reading until there's nothing left while ($line = fgets($fp, 1024)) { $update .= $line; //$content .= $line; }} else { // an error occured when trying to open the specified url } $result = @mysql_query("SELECT * FROM dc_update ORDER BY ID DESC LIMIT 1"); $row = mysql_fetch_array($result); print "FILE UPDATED (BETA)<p>Your Version: $row[version]<p>Availible Version: $update<p>"; $compare = "$row[version]"; if ("$update" == "$compare"){ print "No updates availible<p>"; } else { print "Would You like to update to Version $update now?<br> <form action=$PHP_SELF?view=updateNow method=post> <input type=hidden value=$update name=update> <input type=submit value=\"Update\">"; } } if($id == "updateNow"){ if ($fp = fopen('http://www.MYURL.net/Update.txt', 'r')) { $content = ''; while ($line = fgets($fp, 1024)) { $content .= $line; $myFile = "Update.php"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = "$content"; fwrite($fh, $stringData); fclose($fh); //$content .= $line; }} else { // an error occured when trying to open the specified url } include_once "Update.php"; $result = @mysql_query("SELECT * FROM dc_update WHERE version=\"$update\""); while($row = mysql_fetch_array($result)) { extract($row); } echo "You Have Successfully Installed updates for Version $update.<p> <a href=Updater.php>Go Back</a>"; } ?> Updates.txt (on my website) 3.0 Update.txt (on my website) <?php $sql = "INSERT INTO dc_update SET version = \"$update\", files = \"index.php\""; @mysql_query($sql) or die ("<p>$sql<P>".mysql_errno().": ".mysql_error()); if ($fp = fopen('http://www.MYURL.net/index.php', 'r')) { $content = ''; while ($line = fgets($fp, 1024)) { $content .= $line; $myFile = "index.php"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = "$content"; fwrite($fh, $stringData); fclose($fh); //$content .= $line; }} else { // an error occured when trying to open the specified url } $sql = "INSERT INTO dc_update SET version = \"$update\", files = \"functions.php\""; @mysql_query($sql) or die ("<p>$sql<P>".mysql_errno().": ".mysql_error()); if ($fp = fopen('http://www.MYURL.net/functions.php', 'r')) { $content = ''; while ($line = fgets($fp, 1024)) { $content .= $line; $myFile = "functions.php"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = "$content"; fwrite($fh, $stringData); fclose($fh); //$content .= $line; }} else { // an error occured when trying to open the specified url } ?> Any help / suggestions? Link to comment https://forums.phpfreaks.com/topic/38765-update-files-database-from-remote-files-database/ Share on other sites More sharing options...
clarke78 Posted February 16, 2007 Author Share Posted February 16, 2007 no help at all? Link to comment https://forums.phpfreaks.com/topic/38765-update-files-database-from-remote-files-database/#findComment-186459 Share on other sites More sharing options...
monk.e.boy Posted February 16, 2007 Share Posted February 16, 2007 What's wrong with what you've done? This is what I do with shell scripts + a bit of python. I also do a bit of mysql import and export. These are simple text files. I don't cock around with 'a few rows' I dump everything and import it all on another box. The db is like 300meg. I gzip this, ftp it to another server. Then import it. Trying anything more amazing is premature optimization == bad evil (say if someone changes the db, my backup will still work ) Also set all this up as a cron job that runs at 5:00am. Log everything the script is doing as a RSS file, then every morning check your feeds. monk.e.boy Link to comment https://forums.phpfreaks.com/topic/38765-update-files-database-from-remote-files-database/#findComment-186472 Share on other sites More sharing options...
clarke78 Posted February 16, 2007 Author Share Posted February 16, 2007 Any chance you could go a little more in depth.. i havent set up a cron job before.. and I got a little lost at what you had said you did. Basically I want people to be able to download my set of scripts and be able to check for updates and then update their version from a file on my website. (my scripts use a sql db so I would want those to update through the files somehow.. or have the updater.php be able to take the file from my website and then create / update the db) Link to comment https://forums.phpfreaks.com/topic/38765-update-files-database-from-remote-files-database/#findComment-186481 Share on other sites More sharing options...
clarke78 Posted February 19, 2007 Author Share Posted February 19, 2007 replies? Link to comment https://forums.phpfreaks.com/topic/38765-update-files-database-from-remote-files-database/#findComment-188336 Share on other sites More sharing options...
monk.e.boy Posted February 20, 2007 Share Posted February 20, 2007 I don't understand what you want? If you don't understand cron - google cron. If it is a PHP question then fire away! monk.e.boy Link to comment https://forums.phpfreaks.com/topic/38765-update-files-database-from-remote-files-database/#findComment-189344 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.