Execute PHP script encoded with ZendGuard through command line
Asked Answered
M

2

6

I need to run from the command line (PHP CLI) some files that were encrypted by Zend Guard and php just seems to quit as soon as it reaches an encoded file without any error message. Is it possible to execute PHP scripts that are encoded by Zend Guard from the command line?

More details

In the application I'm currently working on, some tasks needs to be run periodically. At first, we implemented controllers for some urls that where used only to run the tasks. Then we would do a cron job using wget on those pages. The problem is that some of those tasks needed parameters to run. Using wget to do a POST request does not work since the first thing that Zend Guard does is assign a cookie and then do a redirect to the same URL. On the second request, since it's now in GET, all the parameters were lost.

We then decided to move to a command line script to correct the problem. We really like this approach since it solves issues we've had with the URL-based one. First, it does not keep an open Apache connection for an extended period of time. Also, it does not expose some internal logic on public URLs. As I stated earlier, when we try to execute these command line scripts, nothing happens, the application simply quits.

We are using Ubuntu 12.04 LTS, PHP 5.4.25 and Apache 2.2.22. I made sure that the Zend Guard extension was correctly loaded in the command line. Also, it works correctly when the pages are accessed by a web browser.

If anyone can help me with this problem, it would be much appreciated. Thank you!

Monohydroxy answered 10/4, 2014 at 17:18 Comment(3)
Is there anything in your logs about the failure? Have you tried increasing your log level?Hiles
where did you include your zend guard module? can you show the exact details of how and what files in which directories have zend guard module enabled in?Dollie
What about writing a small PHP script which curls the script? First curl opens the connection, gets the cookie and gets redirected. The second curl does a POST request and sends the cookie. Doesn't have the advantages of your second approach but I think it'll work.Unsupportable
A
2

I'm going to make an assumption here. When you guys moved the script to run from command line, you didn't actually re-write the script. You simply just do php -f on the file instead of wget on the URL.

If that's the case, you probably have some logic in the script that requires authentication or web server logic with an exit/die if the param isn't found. You mentioned that some scripts need POST to run, so my guess would be there's a $_POST in there somewhere which obviously won't work on the command line.

Just a guess though.

EDIT: Just read the part where you said it works when you access through URL. Almost definitely a $_POST or something similar.

Asoka answered 17/4, 2014 at 13:59 Comment(0)
T
0

You should wrap any logic you want to run from the command line in your php script inside something like

$cli = isset($_ENV['SSH_CLIENT']);
if($cli) {
  // Code to run from command line here

} else {
  // Code for the Web here


}

This would allow you to have the same file run from the web, and from command line. As tazer84 mentioned -- make sure that in the CLI mode, you do not include Web Only logic (such a header('location: ...');, $_COOKIE, $_POST, etc), and vice-verso.

Thermae answered 20/4, 2014 at 4:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.