PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I'm currently working on a script for a theatre company which has cast lists on their pages about each of their productions. They are connected with an acting agency and want the cast lists to link to each member's profile on the agency website. Each profile is on its own page and named logically so I can work out, given the person's first name and surname, what the address of the page on the agency website should be. This would be simple if all members of the company had profile pages with that agency. Some do not.
Therefore, I need to have a way to test if that member has a profile on the agency's website, hosted elsewhere, and provide a link to their profile if they do and not if not. I know I can use fopen() and test on the return value of that, but I find with some of the larger cast lists its taking a while to generate the pages. Ideally I need a way to just test to see if the page exists on the other server and not actually download the whole thing each time.
I know that file_exists() works with URL wrappers in PHP5, but that's not much help in this situation (the server is running PHP4). I wondered if anyone else had any bright ideas on ways it could be done which might be a little quicker
I'd thought about cURL but it's not available where the site will be running. I'd also just thought of doing it though a socket connection while talking to someone about it on MSN. I'll give that a shot and see if it speeds things up a bit.
OK, well just to follow up and incase its any help for anyone else and for completion, here's what I've done:
It opens the socket connection to the server and, in a loop, does a HEAD request for the page I want to check and has a look at the first line of the response to see if it's a 200. If it is then it links to it, if not, it doesn't. Then with the same connection it requests the next page I want to check and so on. Once I've done all the checking it closes the connection.
I've yet to see if its considerable quicker than the previous method, I'll test it tomorrow.
Thanks for your help
Jonathon
Last edited by ConfuzzledDuck on Thu Aug 25, 2005 8:22 pm, edited 1 time in total.
I've just had a flick though snoopy and it looks as though it would be a little like overkill for what I need, plus I don't think it would give the speed improvements I'm after because it still pulls the whole page each time.
Also I'm trying to use just one persistent connection for all the HEAD calls (sorry, I put GET in the above post, I've edited it now!) so as not to keep opening and closing connections with the remote server. I don't think snoopy can do that (please correct me if I'm wrong).
i am using curl as feyd described. It works i get either a 200 or a 404.
But... i tryed google for documentation on http headers and i didnt get to any easy-understandable and simple coumentation.
Ok, i got the response header, now, to check if the file exists should i just try to mach a "200" is it safe? is the first line allways in that format? i guess thats the way http works but i would like to know this for shure. Like, if i set my server to send "some weird string" on the first like of the header would the client still be able to get the file? or does it only proceeds to the download if it gets a 200?
And BTW, simple "200" string match ... is that a solution with any issues or is it ok?
ok these are dummy questions, we all use a browser everyday, pity we dont know how it works in depth, at least i dont.