View Full Version : [PHP] Class for detecting dead URLs in a given string ...
Wilhelm Murdoch
September 15th, 2008, 11:18 PM
Hey there!
I just wrote a neat little class that can do the following:
- Scan a string for URLs to 'ping' (lulz)
- Add your own patterns for URL matching
- Recursively ping URLs with 3xx redirect responses
- Returns an an associative array with URL => Reponse Code pairs
- Returns codes for ALL known HTTP responses
- Uses both cURL and fsockets for opening connections
This can come in handy for CMSs with older content that may or may not have dead URLs. Great way to do some clean up!
All the other link checking scripts I've found are a bit dated and / or messy, so I wrote my own.
I just need some people to go ahead and hammer away at it to make sure everything works as it should. If you have any suggestions, don't hesitate to throw them my way.
Yes, I also accept constructive criticism.
hl
September 16th, 2008, 12:25 AM
You like comments, don't you?
Wilhelm Murdoch
September 16th, 2008, 12:36 AM
Comments within the code? Yeah, I find it's easier to work with code when you can look at methods and instance variables and know exactly what they do. As long as you have a standard method of commenting, it doesn't look bad. Besides, who knows how many hands a piece of code might go through. This way, people can just pick up and run with it.
PHPDoc is a pretty good standard, anyhow.
As far as any performance issues that commenting may create, it's pretty negligible. The PHP interpreter automatically strips out comments and white space before parsing code.
sekasi
September 16th, 2008, 12:37 AM
You added an author comment to each method?
Interesting.
Wilhelm Murdoch
September 16th, 2008, 12:39 AM
You added an author comment to each method?
Interesting.
Yeah. Not because I'm full of myself, but someone may want to add new methods to the class and then republish. It's probably not necessary, but I've just gotten into the habit of doing it after working on projects with multiple developers.
:)
At least this way you have a good idea of who to go to within your team if a method you didn't write starts acting a bit funny.
hl
September 16th, 2008, 02:25 AM
True. It's a heavy contrast to my typical code though: completely uncommented. You easily have more lines of comments in that one file than I've written in the past year or more. Though, that's probably negative on my end. :P
Wilhelm Murdoch
September 16th, 2008, 02:42 AM
Yeah, as long as I know for a fact that I'm the only one who will ever see the sourcecode of a project I'm working on, I just make sure I stick to a consistent coding style and ditch the comments for the most part. Only issue that's risen because of this is when, years later, I look through the code I wrote and wonder to myself, "What the f%*k was I thinking!?!?"
Wilhelm Murdoch
September 16th, 2008, 10:09 PM
Is it safe to assume that it's working alright? If so, I'll add it to my framework. Muah!!!
hl
September 16th, 2008, 10:23 PM
Mm, I didn't test/really read through it, though I don't see what could go wrong. It's all fairly straightforward.
However, I am interested in the framework you mentioned. :P
Wilhelm Murdoch
September 16th, 2008, 10:56 PM
The framework is named 'Cogsworth'. It's a true MVC-based framework written in PHP and completely open source. What sets this framework apart from the countless others out there is that it was designed specifically to handle multiple applications that can communicate with one another.
Basically Application A can use any controller / model / view of Application B, C or X and vice versa using a concept called 'cross talking'.
Another difference is that the entire presentation layer, or view, was written to take advantage of XML and XSL-based technologies, giving it an almost unprecedented amount of flexibility.
It pretty much goes like this:
1. User places a request
2. The chosen controller processes the request
3. The controller pulls the data from a source using a model
4. All data pulled from the model that is to be displayed to the user is turned into XML
5. The controller pushes the XML to the XSL-based view layer
6. The view parses the XML using XSL and translates it into well-formed XHTML
Not only does this system pretty much force you to write well-formed and standards compliant HTML within the XSL templates, you're also learning an W3C approved and standardized template system. So, instead of learning a proprietary template language, you're learning a new, marketable, skill that you can port over to other systems.
Another feature I've added is called 'domain mapping'. Where you can map domains to specific applications on your Cogsworth install. Let's say you have 10 domains. Rather than having a different shared account for each one to host your sites, you can just park them to a single domain and have Cogsworth point each one to their own application 'workspace'. If domain mapping is activated, Cogsworth does all the routing work for you.
Cogsworth also has an EXTREMELY small running footprint and download size as well:
1. PHPCake MAX compressed download size: 972 KB
2. Zend MAX compressed download size: 12.4 MB
3. CodeIgniter MAX compressed download size: 760kb
4. Cogsworth MAX compressed download size: 76kb
It makes no assumptions on what you may or may not need on start up, so, initially, only the bare minimum group of libraries are instantiated. The main package includes everything you would need to get up and running from an ACL class for security to an Observer class for a highly flexible hook-based plugin system. It also has detailed debugging features when working in 'DEV_MODE' that gives you loverly and easy-to-read error screens. If you want it to it will also log and email you any errors other users encounter when testing your applications.
There's LOTS more it can do and now I'm rambling, but I think other people might like what I've been cooking up. :)
lorren.biffin
October 2nd, 2008, 02:12 PM
Oh gawd I love the idea of cross-talking... :love:
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.