Fread and CPU minutes?

software development

#1

Hi,
I was planing to use php to transfer file to my users since I dont want to reveal the files to everyone. However, using fread() means that the script has to run the entire time (?), and that will be counted toward CPU minutes?
If it’s true, then I can just transfer files to 1-2 users per day, anyone comes up with another solution for file transfer? Would you like to share please?

Thanks^^.


#2

file_get_contents(“file”)?
or:
implode("",file(“file”))


#3

Remember, just because a script’s running doesn’t mean that it’s using the CPU the entire time. It’s entirely coceivable for a script to run for several minutes to hours while only using a few seconds of CPU time, especially when performing a task as lightweight as reading a file. Heck, my laptop’s been up for days, with AdiumX running for days as well, and at last count it’s only used up 1 min, 39s of CPU time.


#4

@Nathan Clayton:
I 'm really new to this CPU minutes term, so really thanks for pointing that out. Do you happen to know how to use php to find out the CPU minutes we used?

@Twirp:
file_get_content add \n at the at of the file, so it wouldnt be good for video file rite? I havent check yet tho.


#5

Typically, the process accounting information is only accessible by the root user on a system, due to the potential misuse of the information by “illicit” users. It seems that the systems here on dreamhost are set up like that.

Unless you were getting hit by an insane amount of people (a la slashdoting/digged), I wouldn’t really worry about the CPU time that you used. This is especially true if you’re using something that’s made to handle lots of simultaneous users like drupal, PunBB, or any of the other free and open-source systems you could use to build your site off of.

If you’re truly worried about getting files leached off of you but don’t want to worry about access restrictions (e.g.: pictures getting leached, etc.), then I’d reccomend that you look into simply setting up a .htaccess file in the directory containing the files you don’t want leeched.


#6

Oh, I see.
This will not happen in years or so^^, but say if I have use fread() to tranfers my homemade clips ^^, each of which is about 200MB to like 100 users perday, can you estimate how much CPU time does it cost?

PS: using .htaccess can prevent ppl from leach your files, but I want to let ppl download my files (with my permission^^). I dont think .htaccess can do that.


#7

Sure you can, check out here on the DreamHost wiki.

Forgot, just remember that the passwords will be sent in plaintext, so don’t use anything important, and you can always change the passwords every month or so if you want to.


#8

I know about this, it’s fast, easy, lightweight, but what if the user share that account somewhere else?
Also, I implement a ticket system that require user to pay certain points per file to download, so it’s not desirable to provide the password to the whole folder.

BTW, I think you have lots of experience with PHP, I’m thinking about using curl-lib instead of file_get_contents/fread, what do you think about it?

Regards,


#9

Not so much PHP experience, but years of experience with Linux systems :stuck_out_tongue:

Another recommendation, check out the site http://www.opensourcecms.com/, maybe there’s a CMS there which provides a majority of the functionality that you’re looking for, something like Joomla or Drupal. Also don’t overlook the contributed modules. Check out those and see what others have use to facilitate file transfers, maybe there’s some useful code that you could use for your site (the beauty of open-source is that it’s so open).