How to Debug Exec() Problems

How can I debug exec() problems?

have a look at /etc/php.ini , there under:

; This directive allows you to disable certain functions for security reasons.
; It receives a comma-delimited list of function names. This directive is
; *NOT* affected by whether Safe Mode is turned On or Off.
; http://www.php.net/manual/en/ini.sect.safe-mode.php#ini.disable-functions
disable_functions =

make sure that exec is not listed like this:

disable_functions=exec

If so, remove it and restart the apache.

For easy debugging I usually like to execute the php file manually (Can request more errors without setting it in the main ini). to do so add the header:

#!/usr/bin/php
ini_set("display_errors", 1);
ini_set("track_errors", 1);
ini_set("html_errors", 1);
error_reporting(E_ALL);

to the beginning of the file, give it permissions using chmod +x myscript.php and execute it ./myscript.php. It's very heedful especially on a busy server that write a lot to the log file.

EDIT

Sounds like a permissions issue. Create a bash script that does something simple as echo "helo world" and try to run it. Make sure you have permissions for the file and for the folder containing the file. you chould just do chmod 755 just for testing.

PHP and shell_exec

Thanks for your answers, but none of them worked :(. I decided to implement in a dirty way, using busy waiting, instead of triggering an event when a record is inserted.

I wrote a backup process that runs forever and at each iteration checks if there is something new in database. When it finds a record, it executes the script and everything is fine. The idea is that I launch the backup process from the shell.

PHP Debugger hangs when calling exec('php ...')

This happens because when you exec second script, xdebug is already busy, so innder script stalls, and execution of outer script cannot be continued.

To deal with this problem:

  1. comment off the xdebug settings in php ini and check environment variable XDEBUG_CONFIG not to contain any
  2. start main script with xdebug parameters (php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1)
  3. exec second script without xdebug parameters: exec('php script.php')

To debug inner script, start first script without xdebug, and exec with xdebug, vice versa.

How to debug the entry-point of fork-exec process in GDB?

You should use this option:

set follow-fork-mode mode

Where mode is one of parent, child or ask.

To follow the parent (this is the default) use:

set follow-fork-mode parent

To follow the child:

set follow-fork-mode child

To have the debugger ask you each time:

set follow-fork-mode ask

So basically you'd start out connecting gdb to A, then set gdb to follow the child, and then when A spawns P, gdb will connect to P and detach from A.

How to debug exit status 1 error when running exec.Command in Golang

The solution is to use the Stderr property of the Command object. This can be done like this:

cmd := exec.Command("find", "/", "-maxdepth", "1", "-exec", "wc", "-c", "{}", "\\")
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &stderr
err := cmd.Run()
if err != nil {
fmt.Println(fmt.Sprint(err) + ": " + stderr.String())
return
}
fmt.Println("Result: " + out.String())

Running the above code, would make it clear what the issue is:

exit status 1: find: -exec: no terminating ";" or "+"

Edit:

In the code above, we expect that in case of error, the messages will be printed to stderr and the command will return a non-zero error code. This is more or less standard.

However, as mentioned below by @snorberhuis, some commands print the errors to stdout. Other commands might print to stderr but return an error code of 0 (in which case err will be nil). And having messages in stderr doesn't necessarily mean there's an error (ffmpeg tools do this a lot).

So basically you might need to tweak the code above to accommodate the commands you expect.

exec not properly executing php command centos 7

Try to execute your command like this from shell

su -s /bin/bash -c "xls2csv -x /usr/share/nginx/html/price_list_EN.xls -s cp1252 -d 8859-1 > /usr/share/nginx/html/price_list_EN.csv" www-data(your webserver user name)

then you debug the error



Related Topics



Leave a reply



Submit