Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #14798

Re: Running same code multiple times, while only changing two parameters

From "J.O. Aho" <user@example.net>
Newsgroups comp.lang.php
Subject Re: Running same code multiple times, while only changing two parameters
Date 2015-01-04 19:13 +0100
Message-ID <cgte6nFfurfU1@mid.individual.net> (permalink)
References <7a2f6bc8-1f1d-4e65-98ea-f9d4f80e8c0b@googlegroups.com>

Show all headers | View raw


On 04/01/15 17:47, semeon.risom@gmail.com wrote:
> Hello -
>
> Beginner at PHP. I'm attempting to run the piece of code (attached below) that will generate an image.
> What I'm attempting to do is run the same piece of code 600 times to create 600 images.
> The only change is two parameters labeled "orientation" and "frequency", which I have a list of values I'm hoping to feed into the code.

You need to make it into a function which takes the which takes all the 
variables that can change as in parameters.

function generate_my_picture($var1, $var2) {
	/* the code here */
}

Then you can make a for-loop or something that generates the images in 
question by calling the function with the different values.


> As it is, the code gives the option of including each value into their respective parameters at once,
> but unfortunately creates an image for all possible pairs of values (600^2, I think).

Remove the foreach you don't need, just use the static value you need 
for that variable.


> I also get the following message if I exceed a 30 second loading time:
>
> "Fatal error: Maximum execution time of 30 seconds exceeded in /home/cogscinl/public_html/files/software/gabor/libgabor.php on line 69

This for your php.ini (my be in control of your web hosting company) 
limits the execution time to 30 seconds, if it takes longer, it will 
stop the execution of the script.

Scripts that executes a long time ain't meant as web pages, but cli 
script would be a better option, as you will not be limited in execution 
time.



> if (array_key_exists("generate", $_GET)) {
> 	$orient = $_GET["orient"];
> 	$size = $_GET["size"];
> 	$std = $_GET["std"];
> 	$env = $_GET["env"];
> 	$freq = $_GET["freq"];
> 	$phase = $_GET["phase"];
> 	$red0 = $_GET["red0"];
> 	$green0 = $_GET["green0"];
> 	$blue0 = $_GET["blue0"];
> 	$red1 = $_GET["red1"];
> 	$green1 = $_GET["green1"];
> 	$blue1 = $_GET["blue1"];
> 	$red2 = $_GET["red2"];
> 	$green2 = $_GET["green2"];
> 	$blue2 = $_GET["blue2"];


This is really bad and dangerous way of handling user input, you should 
ALWAYS validate the data before use.


-- 

  //Aho

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Running same code multiple times, while only changing two parameters semeon.risom@gmail.com - 2015-01-04 08:47 -0800
  Re: Running same code multiple times, while only changing two parameters "J.O. Aho" <user@example.net> - 2015-01-04 19:13 +0100
    Re: Running same code multiple times, while only changing two parameters semeon.risom@gmail.com - 2015-01-04 13:18 -0800
  Re: Running same code multiple times, while only changing two parameters Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-01-04 20:58 +0000
    Re: Running same code multiple times, while only changing two parameters semeon.risom@gmail.com - 2015-01-04 13:15 -0800
      Re: Running same code multiple times, while only changing two parameters "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-01-04 23:21 +0100
  Re: Running same code multiple times, while only changing two parameters Richard Damon <Richard@Damon-Family.org> - 2015-01-04 16:21 -0500
  Re: Running same code multiple times, while only changing two parameters Denis McMahon <denismfmcmahon@gmail.com> - 2015-01-04 22:22 +0000
    Re: Running same code multiple times, while only changing two parameters Denis McMahon <denismfmcmahon@gmail.com> - 2015-01-04 23:10 +0000
      Re: Running same code multiple times, while only changing two parameters Denis McMahon <denismfmcmahon@gmail.com> - 2015-01-04 23:14 +0000
        Re: Running same code multiple times, while only changing two parameters semeon.risom@gmail.com - 2015-01-05 12:47 -0800
          Re: Running same code multiple times, while only changing two parameters semeon.risom@gmail.com - 2015-01-05 12:50 -0800
            Re: Running same code multiple times, while only changing two parameters Denis McMahon <denismfmcmahon@gmail.com> - 2015-01-06 00:42 +0000
              Re: Running same code multiple times, while only changing two parameters Denis McMahon <denismfmcmahon@gmail.com> - 2015-01-06 18:59 +0000
          Re: Running same code multiple times, while only changing two parameters Denis McMahon <denismfmcmahon@gmail.com> - 2015-01-06 00:28 +0000

csiph-web