Page 1 of 1

Mirroring files in php

PostPosted: Sat Nov 01, 2008 6:18 pm
by TheeMahn
I use this script to copy files from one server to another with out having to directly upload the file it is very fast it will transfer at the speed of the slowest server (I typically see 30 megabytes per second), first you need to create a folder on your server and chmod it to 777 (.htaccess protect it if you are worried about hackers climbing in and using it maliciously) You will also need to set the script executable.

This script has saved me tons of time in uploading setting up a mirror and would like to help any one interested.

A modification of your php.ini file may / or may not be necessary, most hosts disable fopen (godaddy is one of them)

open the php.ini and edit the line that says:
Code: Select all
allow_url_fopen = off

and switch it on, enough babbling over the tech no garble on to the script:
Code: Select all
<?php
define('BUFSIZ', 65536);
$url = 'http://downloadubuntusoftware.info/ultimate-edition-1.9-x64.iso';
$dir = '/home/content/d/o/w/downloadue/html/WhereYouUploadThisScript/';
$rfile = fopen($url, 'r');
$lfile = fopen($dir . basename($url), 'w');
while(!feof($rfile))
fwrite($lfile, fread($rfile, BUFSIZ), BUFSIZ);
fclose($rfile);
fclose($lfile);
?>


Now explanation:
BUFSIZ is how much memory will be sucked from your server to grab the chunks, I max it out have tried other sizes, but max of my server seems to yield the best results.

$url is the location of the file you wish to mirror.

$dir is the absolute location to store the file on the mirror (chmod 777 is essential or the script will fail).

The difference this makes even with the 30 sec restriction it takes me ~8 hours to upload a 1 GB file this script takes 5 or 6 minutes to do the same.

If someone can tell me a better way to accomplish this task I am all ears.

TheeMahn

Re: Mirroring files in php

PostPosted: Sun Nov 02, 2008 2:47 am
by tuxsax
Can you explain where the 30 sec limit is coming from?
I want to see if I can think of a way to work it around...

Re: Mirroring files in php

PostPosted: Wed Nov 19, 2008 4:55 pm
by TheeMahn
zivley wrote:Can you explain where the 30 sec limit is coming from?
I want to see if I can think of a way to work it around...



The hosting company sets restrictions (30 sec cpu time) on php scripts

Re: Mirroring files in php

PostPosted: Thu Nov 20, 2008 9:17 am
by tuxsax
Ohhh, that's why! well ten nothing you can do unless you can gain access to their php.ini...

Re: Mirroring files in php

PostPosted: Fri Apr 16, 2010 11:46 pm
by jedc53
The php-mirror has the ability to search projects and downloads for a certain term.You can include ZIP file of the requested file as well as editing the name of a file.You need update the script and added support for two more file hosts.You can access the php.ini.

Re: Mirroring files in php

PostPosted: Fri Oct 29, 2010 1:12 pm
by hendrleybeton
php-mirror is free so give it a try - no database required! php-mirror can also be used to create a powerful downloads server and can easily be modified to be accessed on a subdomain.