6 Replies - 1474 Views - Last Post: 04 April 2012 - 07:34 AM Rate Topic: -----

#1 amalesev  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 04-April 12

Running a CLI PHP script repeatedly

Posted 04 April 2012 - 05:26 AM

So I am working on a project in which I am taking pictures from an SSH area, running ImageMagick on the picture to crop out what I want and then use the threshold to make it like I want, and then finally run Tesseract OCR on the final picture. I have a new picture coming in to the spot I am taking the pictures from every six seconds and I need the program to run the commands to do all of this every six seconds as the pictures come in forever basically. As of right now, here is my code that I have. I am relatively new to using PHP scripting working for the command line in Ubuntu. So if anyone could help me with some fixes to this code, I would be greatly appreciative.
<?php
function tesseract($image)
{
define($ocmd, `ssh *place i am taking from*`);
fwrite("<pre>$ocmd</pre>");
define("$pic1", "`convert $image -crop 1000x170+350+785 -negate -threshold 42000 $image.tif`");//This is a 1920x1080 hd image
define("$pic2", "`convert $image -crop 600x95+200+550 -negate -threshold 41000 $image.tif`");//This is a 1280x720 hd image
define("$pic3", "`convert $image -crop 650x100+75+550 -negate -threshold 43000 $image.tif`");//This is a 960x720 hd image
define("$pic4", "`convert $image -crop 500x62+175+410 -black-threshold 53% $image.tif`");//This is a 960x540 hd image
define("$cmd2", "`tesseract $image.tif $image.txt`");//command to take the words of the edited image
list($width, $height) = ImageCreateFromJPEG(filename);
define("$area", "($width*$height)");
if ($area == 1920*1080)
	{
	$line = $pic1;
	}
elseif ($area == 1280*720)
	{
	$line = $pic2;
	}
elseif ($area == 960*720)
	{
	$line = $pic3;
	}	
elseif ($area == 960*540)
	{
	$line = $pic4;
	}
	else
		{
		$line = "Please try a picture of another size.";
		}
echo("<pre>$line</pre>");
if ($line != "Please try a picture of another size.")
	{
	echo"<pre>$cmd2</pre>";
	}
}
?>



Is This A Good Question/Topic? 0
  • +

Replies To: Running a CLI PHP script repeatedly

#2 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1004
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: Running a CLI PHP script repeatedly

Posted 04 April 2012 - 05:53 AM

So, hat's the problem with the provided code, apart from the random misuse/abuse of constants?

This post has been edited by RudiVisser: 04 April 2012 - 05:54 AM

Was This Post Helpful? 0
  • +
  • -

#3 amalesev  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 04-April 12

Re: Running a CLI PHP script repeatedly

Posted 04 April 2012 - 06:03 AM

View PostRudiVisser, on 04 April 2012 - 05:53 AM, said:

So, hat's the problem with the provided code, apart from the random misuse/abuse of constants?

I am unsure on how to make it to where this will run every 6 seconds. Also, what do you mean random misuse/abuse of constants?
Was This Post Helpful? 0
  • +
  • -

#4 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1004
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: Running a CLI PHP script repeatedly

Posted 04 April 2012 - 07:21 AM

To run every 6 seconds you would invoke the script every 6 seconds, via a cron job for example. This would not be a concern of PHP.

With regards to the misuse of constants, the way that is coded at the moment is very primitive and would be much better suited to a simple array map of dimensions to commands, something like this:
$map = array(
    '1920x1080' => '`convert $image -crop 1000x170+350+785 -negate -threshold 42000 $image.tif`',
    // etc.
);


I'm not sure exactly that your code would work, have you tested it?
define("$pic1", "`convert $image -crop 1000x170+350+785 -negate -threshold 42000 $image.tif`");//This is a 1920x1080 hd image

This would be defining the constant '' to be that value, because $pic1 doesn't exist.
Was This Post Helpful? 0
  • +
  • -

#5 amalesev  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 04-April 12

Re: Running a CLI PHP script repeatedly

Posted 04 April 2012 - 07:26 AM

View PostRudiVisser, on 04 April 2012 - 07:21 AM, said:

To run every 6 seconds you would invoke the script every 6 seconds, via a cron job for example. This would not be a concern of PHP.

With regards to the misuse of constants, the way that is coded at the moment is very primitive and would be much better suited to a simple array map of dimensions to commands, something like this:
$map = array(
    '1920x1080' => '`convert $image -crop 1000x170+350+785 -negate -threshold 42000 $image.tif`',
    // etc.
);


I'm not sure exactly that your code would work, have you tested it?
define("$pic1", "`convert $image -crop 1000x170+350+785 -negate -threshold 42000 $image.tif`");//This is a 1920x1080 hd image

This would be defining the constant '' to be that value, because $pic1 doesn't exist.

Ok , I appreciate your help very much! I have changed the look of this like you have shown. I have never worked with cron before. How would I set this up (if you know)?
Was This Post Helpful? 0
  • +
  • -

#6 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1004
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: Running a CLI PHP script repeatedly

Posted 04 April 2012 - 07:28 AM

This tutorial on crontab should give you everything that you need to know. Simply set it to execute PHP in the same way that you run it to test your script at the moment.
Was This Post Helpful? 1
  • +
  • -

#7 amalesev  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 04-April 12

Re: Running a CLI PHP script repeatedly

Posted 04 April 2012 - 07:34 AM

View PostRudiVisser, on 04 April 2012 - 07:28 AM, said:

This tutorial on crontab should give you everything that you need to know. Simply set it to execute PHP in the same way that you run it to test your script at the moment.

Thank you very much for your help!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1