I have a PHP script I execute in the background from an exec call. Everything works except for the MySQL functions (they don't exist). If I call the script directly from the browser it works fine. What's happening here? Any ideas?
Thank you for your time
Either your command line php was not compiled with php, or php.ini for your command line php does not have the mysql driver module loaded. You'll need to reconfigure and/or rebuild your php installation.
Probably, php_mysql.so is not enabled in your main php.ini but is enabled in an additional ini file added to Apache with PHPIniDir.
Compare output of phpinfo() called from the command line and from a web script. You should see the difference between the ini files and directories used.
Related
I want to run my php Script from the command line but it always throws an error.
If i run the same Script in a Browser everything works fine. There seems to be a problem with the paths. But the .dll files are in the correct folder. I also tried "Run as Administrator" but the error still exists.
Browser
Console
The reason is that PHP CLI uses different phpini config. you need to set a custom config and load it with new settings:
use this article to create a custom .ini and use it with CLI
You need to use static paths for your includes like
C:\xampp\htdocs\test.php
I'm getting a fatal error on my require_once('directory/file.php'), "failed opening required...". I know the required file is in my php includes folder at c:\PHP_Includes\directory\file.php. When I look at phpinfo() I see the correct include_path: ".;c:\PHP_Includes"
But in the command line error it says include_path='.;C:\php\pear;C\Projects\project1\classes'
Any idea why the path seems to be different when running command line script?
The problem is related to the fact that WampServer has a multitude of php ini files. Make sure to keep them all in sync with the correct settings to avoid problems when one is used instead of the other.
Very useful info from http://forum.wampserver.com/read.php?2,72804:
There is actually 3 php.ini files in WampServer
This is how they are used...
C:\Wamp\bin\php\phpX.X.X\php.ini This is only used by wampserver and php cli exe. WampServer's menu is built using php and this is the
config file that is used. It is also used if you are using php through
the command line interface. You generally never need to edit this
file.
C:\Wamp\bin\php\phpX.X.X\phpforapache.ini This is a copy of the php.ini file used for your websites. When this version of php is being
used this file is copied into the apache bin folder. If you change
version of php the apache\bin\php.ini is then emptied and the
phpforapache.ini of the new version of php is loaded into whichever
version of apache is loaded.
C:\Wamp\bin\apache\apacheX.X.X\bin\php.ini This is the actual php.ini that is loaded for your websites. provided that this is the
version of apache being used. This is copied from the relevant active
php folder( phpforapache.ini).
This may seem a little confusing but it is nessecary for WampServer's
ability to change version of apache and php easily. The best thing to
remember is..
If you want to manually edit your php.ini file for websites then
always use the wampserver menu to open it . >> left click the
WampServer icon > php > php.ini
If you want to manually edit your php.ini file for command line then
open php.ini in the current php folder.
My setup is as follows: Windows 7, XAMPP with Apache and PHP enabled I have a PHP script in which I call an external program to do run a conversion. This external program is an EXE file, which requires 3 attributes:
The source file
The destination file
Additional flags (conversion type etc)
When I use the command line tool built into XAMPP to execute my script, everything works fine. But when I use the exec() function in my PHP script, no output file is created. I'm pretty sure the conversion is actually happening (it takes about 5 seconds, about the same time it takes to run the PHP script).
I think it's a permissions thing, so I already moved the EXE file to the same folder as my PHP file and adjusted the permissions of the entire folder (I granted all permissions to all users). I also disabled the Windows UAC and tried to put the command in a BAT file. The file just is not created.
Any help or tips would be greatly appreciated!
My PHP code is as follows:
exec('c:\converter.exe c:\src.txt c:\dst.txt -f', $output);
print_r($output);
When I print out $output, the array turns out to be empty. When I put the exact same command in Command Prompt, the code works like a charm (no syntax errors). I use absolute paths as well.
Try to copy your executable file in same folder as your application.
try
exec("script.exe src.txt dst.txt", &$output);
echo $output;
also, do not forget to use escapeshellcmd() to add some security to your application.
Thank you very much for your input! As it turns out, it was Windows issue caused by the 'Interactive Services Detection' feature. Apache was running as a system service, which prevented calls to external programs (with a GUI). I disabled the run-as-service feature in XAMPP, which solved the problem. A more thorough explanation can be found here: http://php.net/manual/en/book.exec.php
I'm trying to call the nbtstat command from PHP using shell_exec(). Apparently that doesn't work because I'm using a 64-bit system.
echo shell_exec("nbtstat");
I've done some research and it seems that the problem is caused by the fact that Windows 64-bit defaults to \Windows\SysWOW64 as System32 folder. But nbtstat is located in the normal \Windows\System32 folder.
In normal applications you can call Wow64DisableWow64FsRedirection to disable this redirection, but I haven't managed to find this in PHP yet.
Is there a way to actually call these commands from PHP within a 64-bit Operating System?
Add "\Windows\Sysnative" to the end of your environment path.
What you need to do is to grant the IUSR_<machinename> user Read & Execute / Read permissions not on the C:\WINDOWS\SysWOW64\nbtstat.exe file, but instead on the C:\WINDOWS\SYSTEM32\nbtstat.exe file.
I have an exe file that I'm calling through php using the 'system' command. The exe file then makes calls to Microsoft mapi for some reason that i don't know the mapi is not getting initialized when i call the exe through php but if i run the exe from command line it works fine. Any clue why?
p.s I m running iis on 2008 server
This likely has to do with permissions. PHP will run under whatever user account IIS is configured for that resource.
Also, make sure your paths are correct. If you haven't already, start by explicitly defining the path.