PHPNewbie55 Posted March 19, 2009 Share Posted March 19, 2009 Is there a way to open a file and execute the contents of that file just like a person would if they opened the file in a browser? I have looked all through this page: http://us.php.net/manual/en/function.fgetss.php And I have tried to find a way to do this but haven't had any results.... Any suggestions?? Quote Link to comment Share on other sites More sharing options...
jackpf Posted March 19, 2009 Share Posted March 19, 2009 Well, if you simply want to display file contents, you can use something like file_get_contents() or fopen() However, if you actually want to execute the file, you can use something like exec() or system() Hope this helps. Quote Link to comment Share on other sites More sharing options...
PHPNewbie55 Posted March 19, 2009 Author Share Posted March 19, 2009 Thanks but those won't work... What I am looking to do is spider a bunch of links on a page just as if a person clicked on them.. in order to run the queries on the individual pages.. If it was a matter of a few links I would just click on them.. but there are 1000's of links I need to "click on"... Quote Link to comment Share on other sites More sharing options...
pkSML Posted March 19, 2009 Share Posted March 19, 2009 You can use file_get_contents to grab the HTML source and then run it through a parsing function to scape links. You won't be able to run this indefinitely-running script through your browser unless you had a customized ajax interface (think $100's). You'll need to run this on the command line. Quote Link to comment Share on other sites More sharing options...
PHPNewbie55 Posted March 19, 2009 Author Share Posted March 19, 2009 How would I do it through the command line...?? Quote Link to comment Share on other sites More sharing options...
pkSML Posted March 19, 2009 Share Posted March 19, 2009 Run the command line (Start --> Run --> cmd.exe) navigate to the directory with the script in it. find the location of your php.exe. type in something like this: c:\php5\php.exe -f spider.php Quote Link to comment Share on other sites More sharing options...
PHPNewbie55 Posted March 20, 2009 Author Share Posted March 20, 2009 There has got to be a way to do this without going through the command line... When a spider crawls my site for example and hits a page with search.php?q=search term it executes the query using the ?q=search term as a parameter... so there has got to be a way to "crawl" links and execute the php code on the page.. like a bot... feed it a bunch of urls and let it go until the end... I am just looking for the correct function to use to open a link There has got to be some way to do it... ??? Quote Link to comment Share on other sites More sharing options...
samshel Posted March 20, 2009 Share Posted March 20, 2009 include("http://www.domain.com/file.php?search=q1"); include("http://www.domain.com/file.php?search=q2"); include("http://www.domain.com/file.php?search=q3"); when u include a URL, PHP actually gives a hit to that URL as if a user has clicked on it and then includes the HTML output.. check if this is what u need. It may require some php.ini configurations to allow to read a URL. Quote Link to comment Share on other sites More sharing options...
PHPNewbie55 Posted March 20, 2009 Author Share Posted March 20, 2009 That sounds like it might just work but my server won't allow any variables in the urls like php?search=q1 It wouldn't be that bad either each page is less that 1kb so it wouldn't take too long.... What I need to do is run about 1000 individual queries on a search page.. but the search page does a little more than search.. it updates the results in the table... it is hard to explain.. I could probably reset the ini with something like this IF.. I knew what to set it to... LOL I don't mess with my PHP.ini much ini_set ("????", "????"); ANY SUGGESTIONS...? Quote Link to comment Share on other sites More sharing options...
corbin Posted March 20, 2009 Share Posted March 20, 2009 file_get_contents would be better than include for that. Actually, fsockopen could be the fastest since you could use keep-alive connections that way. Quote Link to comment Share on other sites More sharing options...
PHPNewbie55 Posted March 20, 2009 Author Share Posted March 20, 2009 OK I tried fsockopen and got this.... (Unable to find the socket transport "http" - did you forget to enable it when you configured PHP?) So how would I enable fsockopen...?? Like I said I don;t mess with my PHP.ini much... if ever.. Quote Link to comment Share on other sites More sharing options...
corbin Posted March 20, 2009 Share Posted March 20, 2009 It looks like your host has remote requests of all kinds disabled x.x. You don't technically need to use http:// though. Actually, to get the advantage of keep-alive connections, you can't do that. You would just use the host name and port, then you would write HTTP headers to the socket then read back the response. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.