Jump to content

Multiple Instances


trix21

Recommended Posts

I want to be able to run a script more than once using a foreach loop with an include (code below):

<?php

error_reporting(E_ALL);
ini_set('display_errors',1);

$path = '/opt/local/bin/';

$order[0]['type'] = "beach";
$order[0]['first'] = "chris";
$order[0]['second'] = "amanda";

$order[1]['type'] = "chairs";
$order[1]['first'] = "chris";
$order[1]['second'] = "amanda";

$order[2]['type'] = "golf";
$order[2]['first'] = "chris clemmons";

$order[3]['type'] = "heart";
$order[3]['first'] = "chris";
$order[3]['second'] = "amanda";
$order[4]['third'] = "6/10/10";

$order[4]['type'] = "lakeside";
$order[4]['first'] = "chris";
$order[4]['second'] = "amanda";

$order[5]['type'] = "stadium";
$order[5]['first'] = "chris clemmons";

$order[6]['type'] = "swan";
$order[6]['first'] = "chris";
$order[6]['second'] = "amanda";

$order[7]['type'] = "wine";
$order[7]['first'] = "chris";
$order[7]['second'] = "clemmons";

$order[8]['type'] = "horse";
$order[8]['first'] = "chris";
$order[8]['second'] = "amanda";

$c=1;

foreach($order as $o) {
   $first = $o['first'];
   $second = $o['second'];
   $third = $o['third'];

   include($o['type'].'/script.php');

   $c++;
}

 

As you can see near the bottom is where I'm including the script to render an image... these scripts are using ImageMagick to create the image... but I have to wait until it's finished before the loop continues with the next.

If you haven't guessed, if it could run through the loops without holding up on running one script at a time it would render much faster depending on the server spec's (cpu/ram etc...). I have also tried calling the script through exec() with no $return but it still waits until it's finished.

Example from one of the scripts:

<?php

$bg = 'heart/back/bg.jpg';
$font = 'heart/font/itcblk.ttf';
$final = '_FINAL/';

$text = $first;
$text3 = $second;
$text3 = $third;

$text = ucfirst(strtolower($text)).' &';
$text2 = ucfirst(strtolower($text2));
$text3 = date('m.d.y', strtotime($text3));

$compolay = $path.'convert -size 500x170 -gravity center -background none -fill "#010101" -font '.$font.' label:"'.$text.'" comp1.png';
exec($compolay, $result);

$compolay = $path.'convert -size 500x170 -gravity center -background none -fill "#010101" -font '.$font.' label:"'.$text2.'" comp2.png';
exec($compolay, $result);

$compolay = $path.'convert -size 500x170 -gravity center -background none -fill "#010101" -font '.$font.' label:"'.$text3.'" comp3.png';
exec($compolay, $result);

$finalout = $path.'convert '.$bg.' comp1.png -geometry +970+1350 -composite comp2.png -geometry +970+1470 -composite comp3.png -geometry +970+1570 -composite -compress jpeg '.$final.$c.'final.pdf';

exec($finalout, $result);
exec('rm comp1.png comp2.png comp3.png', $result);

?>

 

All script are bassically the same thing but with different images rendered.

 

So just curious if anyone out there would know of such a way of doing this.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/205598-multiple-instances/
Share on other sites

Hello there,

I'm not sure if I can help. 'Threading' (running multiple processes at once) is not a php feature. If you're using a server you have full control of though (not shared hosting), you could probably call multiple system commands that run multple php scripts (your system CAN run multiple things at once).

 

I did a search for 'php threading' on google and came up with some interesting reads. That's not a full answer, but hope that inspires something. :)

 

Best regards,

 

Link to comment
https://forums.phpfreaks.com/topic/205598-multiple-instances/#findComment-1075969
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.