homepage Welcome to WebmasterWorld Guest from 54.161.214.221
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Read log file with PHP?
capulet_x




msg:3329453
 4:49 am on May 3, 2007 (gmt 0)

It turns out that opendir and a number of other cool PHP features are disabled by my host. I've had to deal with similar issues before and have worked around them (that's part of the fun.)
What I am trying to do is create a PHP file which will delete specific files from a directory that are more than 24 hours old.
My question is this:
Is this possible without readdir and opendir? Can I use fopen and fread as alternatives in my solution?
The key problem that I see is that I can read the log file but where do I begin to parse the log file into file names and dates?
Typical entries in my log file would look like this:

2007/05/02 2:00:31 :
File http://www.example.com/myFile.zip
Sent to someone@example.com

2007/05/02 2:08:31 :
File http://www.example.com/myPic.jpg
Sent to someone2@anotherexample.com

I guess I would have to somehow define the format of each entry? If so how would I do this.
Is this idea even realistic with PHP?
If anyone has any ideas or ideas about different approaches please let me know.
Thanks.

postscript: okay, that's more than one question.

 

capulet_x




msg:3329465
 5:09 am on May 3, 2007 (gmt 0)

Oh, I forgot to mention, that I need to extract the time and file name so that I can identify which files to delete. This might f already been obvious but no harm in clarifying.

jatar_k




msg:3329677
 11:48 am on May 3, 2007 (gmt 0)

can you use the directory class?
[php.net...]

Ninjabear




msg:3329882
 3:48 pm on May 3, 2007 (gmt 0)

Could you not just check the file creating time using fstat or similar function and then just use unlink to delete the file?

[uk2.php.net...]

adb64




msg:3332417
 9:13 pm on May 6, 2007 (gmt 0)

Does your host allows you to use the FTP functions [php.net] of PHP? You then may use these to FTP to your server and delete the files using ftp_delete [php.net].
FTP also provides functions for reading, creating and deleting directories.

capulet_x




msg:3332579
 1:22 am on May 7, 2007 (gmt 0)

I looked into all of the suggestions submitted here and each has its own merit, however, it seems that my biggest hurdle is that I won't necessarily know the names of these files to target them. I only know where they will be. Also I can't delete all of the files at once only those that are more than 24 hours old. That's why I thought in lieu of the functions not available to me because of shared server constraints (noted at the beginning of this post) I thought I could create a script to parse the information I needed from my detailed log files to identify specific files that met the criteria for deletion. I didn't glean that I could do this with the examples suggested. If I am wrong could someone elaborate on how I would apply the presented options?

adb64




msg:3332779
 8:05 am on May 7, 2007 (gmt 0)

If I understand your posts correctly you have a log file in the format described in your first post.
Is this format fixed or can you change the script that writes this logfile so it writes one entry per line in a format that can be parsed easily by another script like e.g.:

2007/05/02 2:00:31 http://www.example.com/myFile.zip someone@example.com
2007/05/02 2:08:31 http://www.example.com/myPic.jpg someone2@anotherexample.com

Is this possible? If not we have to make a more complex parser to parse the logfile in the format you described.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved