If this is your first visit, check our documentation. To post, register or login.
Forums / General Questions / Running custom admin scripts from PHP CLI?

Running custom admin scripts from PHP CLI?

Started by mdegrandis on 21 Jul 2011, 3:15 PM · Views: 949

Results 1 to 5 of 5
21 Jul 2011, 3:15 PM
#1
mdegrandis avatar

mdegrandis

New Zenner

Join Date:
Jun 2008
Location:
Oregon
Posts:
60
Plugin Contributions:
0

Running custom admin scripts from PHP CLI?

What I want to do: Run a php script in an endless loop from command line (using nohup). The script makes some images with GD library, and takes a while to execute-- running from a browser is too slow.

What it does: It will correctly tell that it is running from CLI and do echo's and other stuff. Then it hits a zen constant, like DIR_WS_CLASSES and spits out a message that it can't find that file.
If I try to load application_top.php it stops execution, and leaves no errors or warnings (that I can find).

Any php guru's have a tip or place to look?

Thanks again!

NiceBadge.com Lifetime guarantee on all badges! Free mock ups, 24 hour turn around time!

21 Jul 2011, 3:23 PM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Re: Running custom admin scripts from PHP CLI?

It's probably croaking because your CLI isn't aware of the current path/cwd and thus isn't able to use those relative paths to find required resources. Fix your CLI ability to know where it's working from and use the appropriate includes_path, and you will likely have more success.

Although, why are you even loading application_top anyway? What specific Zen Cart capability do you need if you're making GD images?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

21 Jul 2011, 3:41 PM
#3
mdegrandis avatar

mdegrandis

New Zenner

Join Date:
Jun 2008
Location:
Oregon
Posts:
60
Plugin Contributions:
0

Re: Running custom admin scripts from PHP CLI?

DrByte:

It's probably croaking because your CLI isn't aware of the current path/cwd and thus isn't able to use those relative paths to find required resources. Fix your CLI ability to know where it's working from and use the appropriate includes_path, and you will likely have more success.

Although, why are you even loading application_top anyway? What specific Zen Cart capability do you need if you're making GD images?
The rest of the mod is an admin page that allows modifying/creating the images. I was trying to off-load that time spent in GD to be processed separately, with Zend_Queue to be specific.
Since it started as a zen cart admin module, most of the code I wrote has a lot of defines I wrote in the zen cart style. Mainly paths for images, and database tables.
I'll see what I can do with your suggestions.

NiceBadge.com Lifetime guarantee on all badges! Free mock ups, 24 hour turn around time!

21 Jul 2011, 8:57 PM
#4
mdegrandis avatar

mdegrandis

New Zenner

Join Date:
Jun 2008
Location:
Oregon
Posts:
60
Plugin Contributions:
0

Re: Running custom admin scripts from PHP CLI?

I figured it out.
The problem went away when I commented out line 210 or so in core.config.php. This is breakpoint 150, and requires init_admin_auth.php.

I did this in an override....

 if(!defined('STDIN') ){
   $autoLoadConfig[150][] = array('autoType'=>'init_script',
                                 'loadFile'=> 'init_admin_auth.php');
 }

And everything seems hunky-dorie!

Thanks again for your help, your advice on the directories was invaluable.

NiceBadge.com Lifetime guarantee on all badges! Free mock ups, 24 hour turn around time!

21 Jul 2011, 9:02 PM
#5
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Re: Running custom admin scripts from PHP CLI?

Um ... be VERY careful there!!!!
If you skip running init_admin_auth then you have NO security on your admin logins!

I see you're using STDIN as a qualifier, which provides some measure of safety. But ANYBODY READING THIS DISCUSSION SHOULD USE EXTREME CAUTION when making such changes!!!!!!!!

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.