davidb
11-07-2009, 12:46 PM
Without changing the PHP timeout, I need a way to refresh my search/check of the following code.
This is what it does. Opens mysql and gets all the orders that are maked a shipped(where ID is =4). It then takes the tracking number held in the database and checks its status(via usps's website tracking) Then searches that page for the status of delivered. If it is delivered, it changes the database to reflect delivered.
My issue is because it has to wait for USPS's website to respond, if there are too many queued up, it will time out.
One solution was to just run it again. But this is under the assumption that enough were changed from shipped to delivered(thus not being checked). Obviously this does not work if not enough change status.
I have seen other programs that refresh the browers and continue to work, but I can not find any code or what to search for exactly to get that effect.
I am not looking for someone to write the code or anything, but a link to examples of what I am looking for OR search terms that may help. Code is below
$query = "SELECT * FROM orders_status_history WHERE orders_status_id = '4'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
echo "<center>Database Output</center></b>";
$i=0;
while ($i < $num) {
$status_ID=mysql_result($result,$i,"orders_status_id");
$tracking_number=mysql_result($result,$i,"track_id3");
$history_ID=mysql_result($result,$i,"orders_status_history_id");
$orders_ID=mysql_result($result,$i,"orders_id");
if($tracking_number!= null)
{
echo "<br>";
echo $orders_ID;
echo "      ";
echo $tracking_number;
echo "      ";
$url_post_tn="http://trkcnfrm1.smi.usps.com/PTSInternetWeb/InterLabelInquiry.do?origTrackNum=";
$url = $url_post_tn.$tracking_number;
echo $url;
$data = file_get_contents( $url );
if (strlen(strstr($data,'Status: <span class="mainTextbold">Delivered</span>'))>0 || $tracking_number=='9101785091401226548236') {
echo "      DELIVERED";
mysql_query("UPDATE orders_status_history SET orders_status_id='3' WHERE orders_status_history_id='".$history_ID."'");
mysql_query("UPDATE orders SET orders_status='3' WHERE orders_id='".$orders_ID."'");
}
else
{
echo "      Not Delivered";
}
}
$i++;
}
mysql_close();
This is what it does. Opens mysql and gets all the orders that are maked a shipped(where ID is =4). It then takes the tracking number held in the database and checks its status(via usps's website tracking) Then searches that page for the status of delivered. If it is delivered, it changes the database to reflect delivered.
My issue is because it has to wait for USPS's website to respond, if there are too many queued up, it will time out.
One solution was to just run it again. But this is under the assumption that enough were changed from shipped to delivered(thus not being checked). Obviously this does not work if not enough change status.
I have seen other programs that refresh the browers and continue to work, but I can not find any code or what to search for exactly to get that effect.
I am not looking for someone to write the code or anything, but a link to examples of what I am looking for OR search terms that may help. Code is below
$query = "SELECT * FROM orders_status_history WHERE orders_status_id = '4'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
echo "<center>Database Output</center></b>";
$i=0;
while ($i < $num) {
$status_ID=mysql_result($result,$i,"orders_status_id");
$tracking_number=mysql_result($result,$i,"track_id3");
$history_ID=mysql_result($result,$i,"orders_status_history_id");
$orders_ID=mysql_result($result,$i,"orders_id");
if($tracking_number!= null)
{
echo "<br>";
echo $orders_ID;
echo "      ";
echo $tracking_number;
echo "      ";
$url_post_tn="http://trkcnfrm1.smi.usps.com/PTSInternetWeb/InterLabelInquiry.do?origTrackNum=";
$url = $url_post_tn.$tracking_number;
echo $url;
$data = file_get_contents( $url );
if (strlen(strstr($data,'Status: <span class="mainTextbold">Delivered</span>'))>0 || $tracking_number=='9101785091401226548236') {
echo "      DELIVERED";
mysql_query("UPDATE orders_status_history SET orders_status_id='3' WHERE orders_status_history_id='".$history_ID."'");
mysql_query("UPDATE orders SET orders_status='3' WHERE orders_id='".$orders_ID."'");
}
else
{
echo "      Not Delivered";
}
}
$i++;
}
mysql_close();
