Hi, can anyone help me with building a script that submits a URL over and over again? im pretty new at php and im just starting to learn how to use codes and stuff. basically the whole idea is i use a urlsubmitter.php script then open command prompt and use the script from there - and its supposed to keep sending the URL i specify on the script.

so can anyone help me with the script? again, i am really new at this and some direction as to where to go or what to do would help coz im getting confused reading all these codes from tutorial sites and not knowing what to do with all of them! :S

Hi.

So, basically, you want to make a PHP script that is executed via the Windows Command Prompt, which repeatedly calls another PHP script on the web?

What is the point of all this?

well it might sound stupid but i want to use it to avoid delays when clicking links on myspace apps. idno if this is the place to find answers but if you guys cant help then its all good. and yea basically i want to make a PHP script that is executed via the Windows Command Prompt, does not call another PHP script on the net but performs the task of submitting urls on a browser if that makes any sense

You don't really need to go through a browser to call a URL. PHP can do that directly.

For example, this script would fetch Google's home-page every 500ms.

<?php
while(true)
{
  file_get_contents("http://www.google.com");
  usleep(500000);
}
?>

would that be the same as going to the address bar, typing google.com then pressing go every 500ms? if it is, then that means i can just change the url to whatever i want then it will keep going to that url every 500ms?

btw i how would you run a php script? coz i went to cmd and found the location of the php.. then when i typed its name it just opens it.. it doesnt fetch anything or do anything at all

Yes. From the server's point of view, this is basically the same thing as opening the URL in a browser.

If you want to run a PHP script on Windows via the Command Prompt, you need to install PHP on that computer and execute the script using the PHP executable.

To do that, download the ZIP package from php.net/downloads.php. Extract the contents of that file into a directory (Like C:\PHP\ for example).
Then, to execute your script, you can execute a command like so:

C:\PHP\php C:\path\to\my\script.php

You can also add the path to the PHP installation directory to the PATH environmental variable.
Then you can simply call php rather than C:\PHP\php

i downloaded "PHP 5.2.6 zip package [9,516Kb] - 3 May 2008" from the site and extracted it to my F:\PHP folder.. then i used that google script you made as a test script and put it in F:\test.php. after that i went to command prompt and typed "F:\PHP\php.exe F:\test.php" but then nothing happens after pressing enter. 5 minutes later a PHP warning came up on cmd screen saying that it failed to open stream: HTTP request failed on line 4 which is the "file_get_contents" command. is that normal?

Well, yes.

The script is only made to repeatedly call the Google page and ignore the return value.
Then it sleeps for 500ms and repeats.

Unaltered this script would run forever without displaying anything, only reporting warnings when the URL could not be fetched.

Try doing something like this to see some results:

<?php
$successful = 0;
$failed = 0;
while(true)
{
	if(!@file_get_contents("http://www.google.com")) {
		++$failed;
	} else {
		++$successful;
	}
	echo "\r Calls made: $successful ($failed failed)";
	usleep(500000);
}
?>

ok so i realized that php doesnt use the browser cookies.. and just calls the url straight from the script. well the url im trying to call has a "GET parameter name" section with:

opensocial_authtype
opensocial_token
opensocial_url

(im not sure if they matter at all) but im thinking youd have to log on to the site through php to be able to call that particular url since it doesnt use the browsers url.. and ive been looking around and others seem to suggest you log in through stream_context_create() along with file_get_contents() to POST data or use cURL to submit POST requests to log in.

i tried a script like this to log in and then call another url after logging in but i get an error in line 1 for curl_init - but i have cURL installed.

$ch = curl_init('http://url');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
    'username' => 'foo',
    'password' => 'bar'
)));

$response = curl_exec($ch);

although im not sure if you can combine cURL with a test script that has a similar structure to the google one u suggested earlier.. anyway Atli you've been very helpful so far.. if this seems to get nowhere then ill just take the time myselft to figure it out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.