Multiple Headers

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!

Moderator: General Moderators

Post Reply
cyberstryke
Forum Newbie
Posts: 15
Joined: Sun Nov 06, 2005 1:34 pm

Multiple Headers

Post by cyberstryke »

hello to all..

I`m currenly writing a migration scripts for about 6000 records. I`ve been givin instruction to send the record to a URL whici looks like this:


http://256.256.256:256/migrate.cfm?cmd= ... ord&aff=ID...


from what I understand is that this will direct the function migratecust in their migrate.cfm file to pick up all the arguments and insert them in their database.

However my problem here is how i send or automate this process. i can build the URLs for each customer dynamically but I cant send all the URLs or automate it so that it execute one after the other.

I have tried using a for loop and inserting session_start() and session_destroy() but its only the last record that is being migrated.


Any help on this will be very very much apreciated.

Thanks a million in advance..
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

NEVER PASS PASSWORDS AND DATABASE COMMANDS VIA A GET REQUEST.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Get all the required content into an array. Use a foreach() loop. Use get_file_contents() with the URL, and then you can parse the response, if any (eg. if there is a "Inserted Successfully!" message you could identify that with this method).

Page loading might be an issue so you might want to limit the array size by limiting the array insertion process.

eg. instead of calling 6,000 rows from the db into the array use something like LIMIT 0, 300 then LIMIT 301, 600, and etc.
Last edited by m3mn0n on Sun Nov 06, 2005 2:12 pm, edited 1 time in total.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

foobar wrote:NEVER PASS PASSWORDS AND DATABASE COMMANDS VIA A GET REQUEST.
Indeed but when dealing with strictly server-server communication (like I believe he is talking about), the security issue of viewing passwords in the URL of a browser is non-existant. And I do not believe he has control over the destination script, he is bound to the syntax provided.
cyberstryke
Forum Newbie
Posts: 15
Joined: Sun Nov 06, 2005 1:34 pm

Post by cyberstryke »

yes sami, its indeed communication between 2 servers. Actually we are changing one of our poker clients and we need to migrate the existing customers to the new poker platform. Currently we are only migrating to their test platform but later i believe they will ask to send it over SSL.

I will try to use the get_file_contents to see if it works. what if no response come from the url? does it still go to the next url in the loop?

Thanks a lot for your supoort sami. I will try that one and keep you posted on this.

thanks
cyberstryke
Forum Newbie
Posts: 15
Joined: Sun Nov 06, 2005 1:34 pm

Post by cyberstryke »

I was looking for the get_file_contents() function but seems as if I dnt have this. I`m using zend studio 4.0.1.

Any idea on this?

Thanks?
cyberstryke
Forum Newbie
Posts: 15
Joined: Sun Nov 06, 2005 1:34 pm

Post by cyberstryke »

I`ve tried the get_header() function instaed and it seems to be working but now the problem is that my script halt execution after 30 seconds. I remember trying to run a scirpt through command line so that i dnt get the timeout error.

However when trying to run the file from command line it seems that its not doing anything.

The code is as follows:

Code: Select all

for ($i=0;$i<100;$i++)

{
	
	//echo $i;
	
$x=get_headers('http://10.1.1.228/migrate/target.php?i='.$i);

}

and the target.php is as follows:

Code: Select all

echo $i;

$connection = pg_connect("dbname=B_DEV user=postgres host=10.1.1.46");
  if (!$connection) {
    print("Connection Failed.");
    exit;
  }
  
  
 $myresult = pg_exec($connection, "insert into migration_test.migtab(pin) values('$i')"); 
  

if (! $myresult) {
	
	return "failed";
}
	else {
		
		return  "success";
	}


Any suggestion?

Thanks
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

:oops: sorry that should be file_get_contents()

My mistake.

*gets some more caffeine*

It'll return false if the connection to the file/server is not established so you can process an error message from that.

eg.

Code: Select all

<?php
$count = 1;
foreach ($dataarray as $key => $val)
{
    $html = file_get_contents ($the_url_with_the_vars); // connection
    if ($html == FALSE)
    {
        // echo that the processing of $count failed
        } else {
        // parse html responce and retrieve msg if any
     }
  $count++;
}
?>
cyberstryke
Forum Newbie
Posts: 15
Joined: Sun Nov 06, 2005 1:34 pm

Post by cyberstryke »

nice one.. :lol:

Thanks a lot Sami!

It works fine...the data are being migrated successfully but am still having the execution timeout after 30 seconds so that only the first say about 100 records are migrated and then I get that timeout error.

Is there any work around for that?

Thanks..
yum-jelly
Forum Commoner
Posts: 98
Joined: Sat Oct 29, 2005 9:16 pm

Post by yum-jelly »

Put this at the top of your script! Next line after * <?php or <? * !

Code: Select all

ignore_user_abort ( 'true' );
	set_time_limit ( 0 );
If you doing this from a browser, once you start / call the script, you can just close the browser, it will run until it is done doing what you asked it to do in the script!


yj
cyberstryke
Forum Newbie
Posts: 15
Joined: Sun Nov 06, 2005 1:34 pm

Post by cyberstryke »

Thanks yum-jelly..

I will try it and see if it works...


Thanks again for your support. :)
cyberstryke
Forum Newbie
Posts: 15
Joined: Sun Nov 06, 2005 1:34 pm

Post by cyberstryke »

Great its working now..


Special thanks to sami and yum-jelly for their precious help.



Million thanks buddies... :D
Post Reply