Jump to content

[SOLVED] Stop and Continue


nuxy

Recommended Posts

Well, I've made a script that makes random words(letter sequences), but my here is my problem.

It's not really a problem, just a feature I want to enhance.

 

The script will make millions/billions of letter sequences, but that takes a long time.

What I want to do is to be able to stop the script, and then continue it at a later point, from that original point I stopped it.

Say it came to the letter sequence "as1s" and then I stop it, the next time it should go on from "as1s" and make "as1t" and so forth.

 

Here is my current script, a bit messy, but should be doable.

function auto() {
global $mysql;
echo 'Beginning to add hashes..<br><form method="post" action="?auto">
<input type="submit" value="Show No Output" name="blah"></form><br><br>';
$chars = '1234567890abcdefghijklmnopqrstuvwxyz';
for($next[0]=0;$next[0]<=(strlen($chars)-1);$next[0]++) {
	for($next[1]=0;$next[1]<=(strlen($chars)-1);$next[1]++) {
	 for($next[2]=0;$next[2]<=(strlen($chars)-1);$next[2]++) {
	  for($next[3]=0;$next[3]<=(strlen($chars)-1);$next[3]++) {
	   for($next[4]=0;$next[4]<=(strlen($chars)-1);$next[4]++) {
	    for($next[5]=0;$next[5]<=(strlen($chars)-1);$next[5]++) {
	     for($next[6]=0;$next[6]<=(strlen($chars)-1);$next[6]++) {
	      $string = '';
	      if ($next[0]) $string .= $chars[$next[0]];
	      if ($next[1]) $string .= $chars[$next[1]];
	      if ($next[2]) $string .= $chars[$next[2]];
	      if ($next[3]) $string .= $chars[$next[3]];
	      if ($next[4]) $string .= $chars[$next[4]];
	      if ($next[5]) $string .= $chars[$next[5]];
	      if ($next[6]) $string .= $chars[$next[6]];
                            // otehr processing stuff not rellative here..
	    }
	   }
      }
     }
    }
   }
  }
}

 

Also, if anyone knows how to optimize, well, not really optimize, but another way to do this aswell, I would appreciate it.

Anyone have an idea how I can make this feature?

 

Thank you in advance...

Link to comment
Share on other sites

That is my problem, i'm already checking the hashes against a database.

But anyways, I've been working on it, founda partial solution.

 

function auto() {
global $mysql;
$chars = '1234567890abcdefghijklmnopqrstuvwxyz';
echo 'Loading Config: ';
$datafeed = file_get_contents('stats.ini');
$datafile['new'] = split("\n", $datafeed);
foreach($datafile['new'] as $varline) {
	$vars = split(' = ', $varline);
	$var[$vars[0]] = $vars[1];
}
$pre[0] = $var['next[0]'];
$pre[1] = $var['next[1]'];
$pre[2] = $var['next[2]'];
$pre[3] = $var['next[3]'];
$pre[4] = $var['next[4]'];
$pre[5] = $var['next[5]'];
$pre[6] = $var['next[6]'];
echo 'Loaded<br><pre>';
print_r($pre);
echo '</pre><br><br>';
for($next[0]=$pre[0];$next[0]<=(strlen($chars)-1);$next[0]++) {
	for($next[1]=$pre[1];$next[1]<=(strlen($chars)-1);$next[1]++) {
	 for($next[2]=$pre[2];$next[2]<=(strlen($chars)-1);$next[2]++) {
	  for($next[3]=$pre[3];$next[3]<=(strlen($chars)-1);$next[3]++) {
	   for($next[4]=$pre[4];$next[4]<=(strlen($chars)-1);$next[4]++) {
	    for($next[5]=$pre[5];$next[5]<=(strlen($chars)-1);$next[5]++) {
	     $fp = fopen('stats.ini', 'w');
	     $datafeed = file_get_contents('stats.ini');
	     $datafile['new'] = split("\n", $datafeed);
	     foreach($datafile['new'] as $varline) {
			$vars = split(' = ', $varline);
			$var[$vars[0]] = $vars[1];
		 }
		 $var['next[0]'] = (empty($var['next[0]'])) ? 0 : $var['next[0]'];
		 $var['next[1]'] = (empty($var['next[1]'])) ? 0 : $var['next[1]'];
		 $var['next[2]'] = (empty($var['next[2]'])) ? 0 : $var['next[2]'];
		 $var['next[3]'] = (empty($var['next[3]'])) ? 0 : $var['next[3]'];
		 $var['next[4]'] = (empty($var['next[4]'])) ? 0 : $var['next[4]'];
		 $var['next[5]'] = (empty($var['next[5]'])) ? 0 : $var['next[5]'];
		 $var['next[6]'] = (empty($var['next[6]'])) ? 0 : $var['next[6]'];
		 foreach($var as $key => $vl) fputs($fp, $key . " = " . $vl . "\n");
		 fclose($fp);
	     for($next[6]=$pre[6];$next[6]<=(strlen($chars)-1);$next[6]++) {
	      $string = '';
	      if ($next[0]) $string .= $chars[$next[0]];
	      if ($next[1]) $string .= $chars[$next[1]];
	      if ($next[2]) $string .= $chars[$next[2]];
	      if ($next[3]) $string .= $chars[$next[3]];
	      if ($next[4]) $string .= $chars[$next[4]];
	      if ($next[5]) $string .= $chars[$next[5]];
	      if ($next[6]) $string .= $chars[$next[6]];
	      // not relevant to the topic
	    }
	   }
      }
     }
    }
   }
  }
}

 

Still debugging, so I'm still open to ideas..

Link to comment
Share on other sites

try

<?php
function my_next($a, $car = '1234567890abcdefghijklmnopqrstuvwxyz'){
$num = strlen($car);
$add = 1;
$out = '';
for ($i = strlen($a); $i > 0;){
	$x = strpos($car, $a[--$i]) + $add;
	$out = $car[$x % $num].$out;
	$add = floor($x / $num);
}
if ($add) $out = $car[0].$out;
return $out;
}

$start = 'zx';
for ($i = 0; $i <20; $i++){ // or some other condition
echo $start = my_next($start),"\n";
}
// remember last $start and next time use it
?>

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.