Are you a spammer

Please note, that the first 3 posts you make, will need to be approved by a forum Administrator or Moderator before they are publicly viewable.
Each application to join this forum is checked at the Stop Forum Spam website. If the email or IP address appears there when checked, you will not be allowed to join this forum.
If you get past this check and post spam on this forum, your posts will be immediately deleted and your account inactivated.You will then be banned and your IP will be submitted to your ISP, notifying them of your spamming. So your spam links will only be seen for an hour or two at most. In other words, don't waste your time and ours.

This forum is for the use and enjoyment of the members and visitors looking to learn about and share information regarding the topics listed. It is not a free-for-all advertising venue. Your time would be better spent pursuing legitimate avenues of promoting your websites.

Mirroring files in php

Source code I have written openly published for your viewing pleasure.


Mirroring files in php

Postby TheeMahn » Sat Nov 01, 2008 6:18 pm

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
Home of Ultimate Edition. Got a question? Please review the F.A.Q. Browse the How to section.

Main O/S: Builder of O/S Guess.
Mainboard: ASUS Hero VI (AM4)
CPU: AMD 1700X water cooled (Deepcool Captain Genome Cooling tower)
Ram: 16 GB GSkill Trident RGB Series Dual Channel DDR4 3200
Video: MSI RX470 8GB Gaming card.
Hard Disks: MASSIVE on the network.(10 Gigabit, 48 port, multiple servers)
Monitors: Dual 4K 43" LG, 4K Samsung 28"
750 Watt modular PSU (Rosswell)
1100 Watt Amp & 4 X 600 Watt speakers

Servers in the basement.
User avatar
TheeMahn
Site Admin
 
Posts: 4201
Joined: Fri Oct 12, 2007 10:02 am
Location: U.S.A.
Age: 53
Operating System: Ultimate Edition Developer



Re: Mirroring files in php

Postby tuxsax » Sun Nov 02, 2008 2:47 am

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...
______________________________
Two things I love: Linux and my sax
tuxsax
U.E. Master
U.E. Master
 
Posts: 790
Joined: Sat Apr 26, 2008 4:15 am
Age: 53
Operating System: Ultimate Edition Beta Tester



Re: Mirroring files in php

Postby TheeMahn » Wed Nov 19, 2008 4:55 pm

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
Home of Ultimate Edition. Got a question? Please review the F.A.Q. Browse the How to section.

Main O/S: Builder of O/S Guess.
Mainboard: ASUS Hero VI (AM4)
CPU: AMD 1700X water cooled (Deepcool Captain Genome Cooling tower)
Ram: 16 GB GSkill Trident RGB Series Dual Channel DDR4 3200
Video: MSI RX470 8GB Gaming card.
Hard Disks: MASSIVE on the network.(10 Gigabit, 48 port, multiple servers)
Monitors: Dual 4K 43" LG, 4K Samsung 28"
750 Watt modular PSU (Rosswell)
1100 Watt Amp & 4 X 600 Watt speakers

Servers in the basement.
User avatar
TheeMahn
Site Admin
 
Posts: 4201
Joined: Fri Oct 12, 2007 10:02 am
Location: U.S.A.
Age: 53
Operating System: Ultimate Edition Developer



Re: Mirroring files in php

Postby tuxsax » Thu Nov 20, 2008 9:17 am

Ohhh, that's why! well ten nothing you can do unless you can gain access to their php.ini...
______________________________
Two things I love: Linux and my sax
tuxsax
U.E. Master
U.E. Master
 
Posts: 790
Joined: Sat Apr 26, 2008 4:15 am
Age: 53
Operating System: Ultimate Edition Beta Tester



Re: Mirroring files in php

Postby jedc53 » Fri Apr 16, 2010 11:46 pm

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.
jedc53
U.E. Newbie
U.E. Newbie
 
Posts: 4
Joined: Fri Apr 16, 2010 8:05 am
Operating System: Ultimate Edition 3.2 64 BIT



Re: Mirroring files in php

Postby hendrleybeton » Fri Oct 29, 2010 1:12 pm

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.
hendrleybeton
U.E. Newbie
U.E. Newbie
 
Posts: 4
Joined: Fri Oct 29, 2010 8:52 am
Operating System: Ultimate Edition 3.1 64 BIT


Return to Programming

Who is online

Users browsing this forum: No registered users and 7 guests