Jump to content

[SOLVED] Throttaling results from table


dyerucf

Recommended Posts

I have a table of X rows taht I am pulling data out and placing into a query string.  The issue here is that I have to throttle these requests, so for this example I can fire off 3 per second, but the number of rows will grow so I need to use variables and the timing is dynamic as well. 

 

<?php
// IMPORTANT STUFF HERE 
$token = "blah";
$callerID = "4075551212";
$api = "blah";

$ports = 200; 										// Staging you can only use 2 ports at a time
$durration = 60; 									// avg call length is 60 seconds
$dbname="***********";							// DB Vars
$dbpass="="***********";";
$dbuser="="***********";";
$dbhost="="***********";";
$table="contact_test";
// END USER VARS

$con = mysql_connect($dbhost, $dbuser, $dbpass);	// Connect to Contacts DB to start calling
if (!$con)
		{
			 die('Could not connect: ' . mysql_error());
		}

mysql_select_db ($dbname)or die(mysql_error());

$sql="SELECT * FROM " . $table . " ORDER BY no ASC";
$result= mysql_query($sql) 
or die(mysql_error());
$numrows=mysql_num_rows(mysql_query($sql));

$cps = $ports / $durration;						// Throttleing code  CPS = number of ports

//Logic to figure out calls to fire each iteration

echo "Number of calls to fire per second " . round($cps) . "\n";
echo "Number of calls to make " . $numrows . "\n";
$iterations = $numrows / round($cps,0);
echo "Number of Iterations to make " . $iterations . "\n";


	       while($row = mysql_fetch_array( $result ))
         {		
	   echo $row['firstName'] . " ";				 	//print results to screen
	   echo $row['lastName'] . "\n";
	   echo $row['number'] . "\n";
	   echo $row['pin']. "\n";

}

?>

 

 

So in this test case I am working with I have 12 rows / cps = 3, so I have 4 batches to iterate through.  I am just trying to figure out how to build a loop to do this. I am very new to PHP, like 2nd day so any help would be fantastic!

 

Regards,

 

John

 

Link to comment
Share on other sites

Well it boiled down to my unfamiliarity with loops.  Luckily I was able to get some help from work on this issue and its now taken care of.  Soution below for 'posterity's sake' 

 

Thanks!

 

//Logic to figure out calls to fire each iteration
// 
$cps = $ports / $durration;						// Throttleing code  CPS = number of ports
$numrows=mysql_num_rows(mysql_query($sql));
$iterations = $numrows / round($cps,0);
$rounded = round($cps,0);
//Set variables for our batch script
$calling = 1;
$counter = 0;
$batch = 1;

echo "Number of calls to fire per second " . round($cps) . "\n";
echo "Number of calls to make " . $numrows . "\n";
echo "Number of Iterations to make " . round($iterations) . "\n";
echo "\n";

  while($row = mysql_fetch_array( $result )!= null){
  /*
		  echo $row['firstName'] . " ";				 	//print results to screen
		  echo $row['lastName'] . "\n";
		  echo $row['number'] . "\n";
		  echo $row['pin']. "\n";
		 */
		$number = $row['number'];
	echo "data" . $number . "\n"; 
	echo "innerLoop : Calling # [ " . $calling ." ] roundedCPS [ " . $rounded . " ] \n";
 	$counter++;
 	$calling++;
 	if ($counter == $rounded){
 		sleep($delay);
 		$batch++; 
 		echo "Batch number: " .$batch."\n";
 		$counter = 0;
	}
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.