php DOTNET class - works on command line NOT on web browser - php

The below code works from command line .
$full_assembly_string = 'dllname';
$classname= "classname";
$cObj = new DOTNET($full_assembly_string,$classname);
echo($cObj ->SayHello());
But when i try to execute from browser it show the message window - apache has stopped working.
Is there anyone was able to run .net custom dll from php ??
This example works on browser and cmd .
http://php.net/manual/en/class.dotnet.php

Depending on what kind of implementation you're using there can be 2 php.ini files:
1 for command line
1 for server env
i suggest locating and searching for discrepancies between the 2.

Related

nodejs command not executing through PHP on Linux

The problem is faced while running node command (which generates PDF file for given link) on Linux through PHP exec/passthru/system functions. Actually, I am trying to create PDF file through headless chrome using Puppeteer node module. Everything worked fine in Windows system but as soon as the same code was moved on production server (which uses Linux), the exec/passthru commands began to throw 127 return code errors. Please note that same node command works without any problem when run directly on terminal .
Also, Apache has write permissions in directory where file is being generated and command was also tried by giving the absolute paths but nothing seems to be working
The format of command is like this
"node script-generating-code.js http://www.url-of-page.com/"

Unable to run inkscape in PHP shell_exec() command

I have a design tool extension that is used on a website I'm working on. The design tool uses inkscape command line to export images. There is a php interface to work with the command line operations which ultimately calls shell_exec($inkscapeCmd). After noticing the image files weren't being exported, I created a few tests to try and debug. I changed the execute line to shell_exec($inkscapeCmd . ' 2>&1') in order to see the error message:
sh: inkscape: command not found
...which is odd since it's definitely installed and accessible. I added a check for the user on my test page to make sure the commands were being executed by a user with access to inkscape:
$processUser = posix_getpwuid(posix_geteuid());
echo 'user: ' . $processUser['name'];
Then I ssh'd into the server to confirm that I could run the same commands as that user, and was able to run them without any issues (which also confirmed inkscape was in the PATH). I'm able to run other, basic shell commands from PHP without issue, like so:
echo shell_exec('ls');
But now I'm at a loss; I'm not sure what else to check to determine why I'm getting the 'command not found' error. Any direction would be helpful.
The server (rather old, I know):
CentOS 6.7
PHP 5.3.3
Inkscape v0.47
The process does not have the location for inkscape in it's path.
You will have to supply to full path to the executable.
Example
/usr/bin/inkscape
At the command line type 'whereis inkscape' to find is location.

cygwin: can't execute PHP script via PATH

I have written a PHP script "toalpha" (purpose not relevant to this question). The script is in $HOME/bin. If my CWD is $HOME/bin, I can execute it by typing "./toalpha". But if I simply type "toalpha", I get a message:
Could not open input file: /c/barry/bin/toalpha
Some information that may be relevant:
. I recently upgraded my desktop from WinXP to Win7.
. This is the first time that I have made my own userid be an ordinary user instead of an admin. (I tried to do that on XP, but ran into problems and went back to having my normal userid be the admin. Don't need a solution for that because I'm no longer running XP and besides it was my own fault.)
. My $HOME is /c/barry
I did that by adding the following to the .bashrc created when I installed cygwin:
mount C: /c
HOME=/c/barry
cd
. .bashrc
. The first two lines of the PHP script are:
#!/c/xampp/php/php
<?php
. Yes, the copy of PHP I want to use is in C:\xampp\php\php.exe
. I have another, similar script that I wrote on WinXP. It starts with the same two lines. It worked fine under XP, but doesn't work on Win7.
My best guesses at the source of the problem:
A difference between XP and Win7
I fumbled the home directory change in some way. IIRC, when I installed cygwin on XP I did some trickery so it would start directly in C:\barry but I couldn't remember how I did that when I installed it on Win7, so I took the "easy way out".
bash is passing to "C:\xampp\php\php.exe"
the file name "/c/barry/bin/toalpha"
but that is a cygwin path and your PHP does not regognize it.
You should convert it in an understandable one using
cygpath
Try
/c/xampp/php/php $(cygpath -w /c/barry/bin/toalpha )

moodle - database connection failed when running a script

So I am setting up a moodle plugin that syncs groups defined in child courses into a meta course. I managed to install it based on the following instruction.
Installation
Copy the metagroups folder into your Moodle /local directory and visit
your Admin Notification page to complete the installation.
After installation you may need to synchronize existing meta-course groups, to do this run the cli/sync.php script (use the --help switch for further instructions on script usage).
So when i tried to run th sync.php script using this command in there terminal
php -f sync.php
it shows me an error message
I found that the line in the script that is causing this issue is the following line
require_once(DIR . '/../../../config.php');
my config.php file looks like this:
I have no idea why this is happening, as all moodle functionality seems to be working, which means database connection is the way it should be. Does anyone know this is happening and a way around this. Thanks in advance.
By the way, my moodle version is 2.6.3 running in localhost on a mac OSX 10.9
I had the same problem, but running moodle with MAMP.
The simple fix for me was just to add the php path for MAMP (for whichever PHP version I required):
export PATH=/Applications/MAMP/bin/php/php5.6.40/bin/:$PATH
…and then run whatever PHP script I needed!
Just a guess but I'm wondering if its picking up a different config.php
Try specifying the folder for the require_once
require_once('/Applications/XAMMP/moodlewebroot/config.php');
If that works then check the check the output of
echo DIR . '/../../../config.php'
Although it's more common to use dirname() in Moodle eg:
require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
Also some of the command line functions expect to have the dirroot set up in config.
$CFG->dirroot = '/Applications/XAMMP/moodlewebroot';

Dbus PHP Unable to Launch dbus-daemon Without $DISPLAY for X11

I'm using GREE Labs' Dbus PHP Extension in my attempts to make a PHP class that is able to create desktop notifications.
$dbus = $dbus = dbus_bus_get(DBUS_BUS_SESSION);
$message = new \DBusMessage(DBUS_MESSAGE_TYPE_SIGNAL);
$message->setDestination("org.freedesktop.DBus");
$message->setAutoStart(true);
$dbus->sendWithReplyAndBlock($message, 1);
When my code is run I get the following error:
Warning: dbus_bus_get() [function.dbus-bus-get]: failed to create dbus
connection object [Unable to autolaunch a dbus-daemon without a
$DISPLAY for X11] in [...COI/GTK/Notify.php on line 39
This is the first time I've used anything related to dbus, and am rather lost.
I'm aiming for an effect similar to what occurs when one executes the following in a terminal (on Ubuntu 11.10):
/usr/bin/notify-send -t 2000 'title' 'message'
I did initially use notify-send & exec, but switched when I found the GREE Dbus extension as I thought it may provide a cleaner interface. Also notify-send would only work properly if I changed my apache user to be the same as the user I'm currently logged in as - not an ideal solution.
Would anyone be able to either tell me what modifications are required to achieve my desired result, or alternatively tell me if what I want to do is in fact impossible?
Or, is there another way I should be doing this?
Dbus does not like being run while in a command line environment, without X. It's frustrating, but this is what I wrote in python to override that. It comes down to setting two environmental variables.
def run(self):
os.environ['DBUS_SESSION_BUS_ADDRESS'] = "unix:path=/run/dbus/system_bus_socket"
os.environ["DISPLAY"] = ":0"
try:
bus_name = dbus.service.BusName(INTERFACE,
bus = dbus.SessionBus())
dbus.service.Object.__init__(self, bus_name,
'/com/your/path/here')
gobject.MainLoop().run()
except Exception, E:
f = file('/tmp/bus.log', 'a')
f.write(str(E))
f.close()
EDIT: I forgot another very useful way to run dbus on the command line
eval 'dbus-launch --auto-syntax' [command]
I use it on a raspberry pi to run my custom dbus deamons. dbus-launch --auto-syntax is a command that outputs environmental variables and files applicable to dbus in bash. The eval command will take that output and evaluate it so your command will run with those environmental variables.
A simple test would be to run something like this:
eval 'dbus-launch --auto-syntax' python /usr/bin/my-dbus-daemon.py
eval 'dbus-launch --auto-syntax' qdbus org.dbus.method /org/dbus/method/test
Use dbus-launch in the script that starts your web server in order to start an appropriate DBus daemon at the same time. See the dbus-launch(1) man page for details.

Categories