简体   繁体   中英

Execute PHP script encoded with ZendGuard through command line

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!

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM