Page 1 of 1
Multiple Headers
Posted: Sun Nov 06, 2005 1:36 pm
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..
Posted: Sun Nov 06, 2005 2:08 pm
by foobar
NEVER PASS PASSWORDS AND DATABASE COMMANDS VIA A GET REQUEST.
Posted: Sun Nov 06, 2005 2:09 pm
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.
Posted: Sun Nov 06, 2005 2:11 pm
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.
Posted: Sun Nov 06, 2005 2:19 pm
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
Posted: Sun Nov 06, 2005 2:28 pm
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?
Posted: Sun Nov 06, 2005 3:07 pm
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
Posted: Sun Nov 06, 2005 3:11 pm
by m3mn0n

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++;
}
?>
Posted: Sun Nov 06, 2005 6:36 pm
by cyberstryke
nice one..
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..
Posted: Sun Nov 06, 2005 7:03 pm
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
Posted: Mon Nov 07, 2005 11:42 am
by cyberstryke
Thanks yum-jelly..
I will try it and see if it works...
Thanks again for your support.

Posted: Mon Nov 07, 2005 11:51 am
by cyberstryke
Great its working now..
Special thanks to sami and yum-jelly for their precious help.
Million thanks buddies...
