Right, I'll try and explain this the best I can.
I'm using PHP COM with a DLL which has a separate config file. Looking at the code of the COM DLL, no path is specified for the config file, only a filename.
Running through command line with the config file in the same directory is successful, however when running through a webpage, it can't find the config file.
Any ideas?
I would try changing the current working directory:
chdir('somepath/');
http://php.net/manual/en/function.chdir.php
Edit: Failing that, try to see if it is relative to the host process executing your script. For CGI, that's be php-cgi.exe. For a module, it would be whatever your web server is. If that is the case, you can make a link in NTFS to some config within your script if necessary. You might also consider using Process Explorer to try to figure out what file that DLL is trying to open. Although, since you have the source code, you should be able to figure that out by looking at it.
Related
I am facing a puzzle, im testing some scripts on my wamp installation. When i do a echo date('d) and i run the script from the browser i see the correct week day, by example, lets say it echo 'Mon', but.. when i execute it from a batch file, the echo shows the next day, by example 'Tue', why this can be happening? I have the correct timezone in my php.ini the windows clock as well, i dont have a clue why this is happening. In the same puzzle, i have a path to a dbconnect file, again, from browser it run ok, but from the batch file it dont find the included path, i solved it writing the full windows path C:/path/to/file.php but i dont understand why, the include is done by the php file executed by the batch file, so the path should be ok right?
If someone can share some lights i would appreciate it.
In WAMP the CLI uses a separate php.ini file in the PHP installation directory (e.g. C:\wamp\bin\php\php5.3.13) rather than the one under the Apache installation so check the settings in that file for running PHP on the command line.
Using php through the browser is using the CGI/FPM version and with your command line it is the CLI version. CLI and server (cgi/fpm) use different php.ini-files. On cli type
php --ini
To find where your ini file is and correct it.
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 am currently working on a script that I am attempting to automate via cron. Running the script via terminal is just fine, but when I attempt to run the script with crontab, I am getting some issues.
Part of my script loads and validates and xml file via DOMDocument::loadXML() and DOMDocument::validate() and php throws an error when attempting to validate stating:
Failed to load external entity: /linuxuser/homefolder/my_dtd.dtd
Within the xml file, the dtd is set to:
../../../../../../../my_dtd.dtd
Is there some misconfiguration of the server or is it more likely something wrong with my php code at this point? It seems to grab my linux home directory rather than the path relative to the xml file. Just wondering if anyone else has seen an issue like this or could point me in the right direction. Thanks.
Quoting the PHP documentation for differences in CLI usage (command-line interface):
The CLI SAPI does not change the
current directory to the directory of
the executed script!
When PHP scripts are run via CRON, it is executed on the user's home directory. You can either replace all relative path references used by the script to absolute, or place this on the start of the script:
chdir(dirname(__FILE__)); # for PHP 5.2.x and below
# or
chdir(__DIR__); # for PHP 5.3+
Most likely, the problem is in working dir and resolving relative path.
Try absolute path in your xml file.
I just installed Apache and PHP on my computer to be able to run PHP files locally.
I can run a PHP file if it is located in Apache2.2\htdocs directory.
Is that possible to run PHP files outside this directory ?
I'm looking to a simple solution, because all I need is to write a small PHP code and try it locally.
I would like to be able to run the PHP file by right clicking it -> Open with Firefox
You can run a PHP script from anywhere using the command line:
php yourscript.php
There is some ways to do it, but the simplest way is using 'include' or 'required' php command:
<?
include ('/somewhere/outside/of/your/htdocs/file.php');
?>
Please note you may need to turn off 'open_basedir' php directive.
Newer versions of php come with php-cli: a command line interface. So to run php code, you just need to type:
php some_code.php
Or you can change paths in apache config to another dir
you cannot open it with firefox.
Because firefox has nothing to do win PHP.
So, you need to request this URL from a web-server
Create a windows shortcut with http://127.0.0.1/file.php
or whatever way you prefer to click web links
Yes. You don't say if you want to run it from the web server, or from the command line, but you can use include past the web root.
You can either run it from the command line,
or you can create a "wrapper" script within your htdocs that "includes" the file from outside of the htdocs directory
I had always wondered about it the same manner, say you have a folder in a drive either than the apache/htdocs folder in drive C, and you would like to develop directly in this folder. But think about it this way, would you put your folders else where and expect it to be running on the web? Now Way. Why would you do that?
Goto conf folder and open httpd file change
DocumentRoot "C:/your/path" and
Directory "C:/your/path"
This should work
if it says forbidden access go to this link
Error message "Forbidden You don't have permission to access / on this server"
I'm on a Windows machine. This seems like it should be unnecessary, but when I do it, everything suddenly works. Is there something wrong with my path? Do I need to add something to it to avoid having to copy DLLs?
Apache like any application will assume that the file is located in the same directory as the Current Directory path (check out http://en.wikipedia.org/wiki/Working_directory). If it's not there. The current working directory is USUALLY the same directory that httpd.exe (main executable) is in but it can actually be different if you do something like
C:\Apache2>bin\httpd.exe
In this case the Current Working directory is C:\Apache2 rather than C:\Apache2\bin.
If if the file isn't found there the application will naturally traverse the PATH environment variable. The PATH environment variable is a semi-colon or comma separate list of paths) to find the file.
Start -> Run -> Type "cmd.exe" and then in the Command Prompt type "echo %PATH%" to see the current path you have.
Finally, if the file wasn't found it will just error out.
As a tip you can actually track what files an application is trying to load and where they load them from by using Process Monitor. http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx
I've used this tool to solve load DLL problems in Apache before and other applications as well. Just simply add a filter for the app you are running and have it only sniff out file reads.
I donot know the internals of MySQL and apache.
My thought is this. Internal of your application is using libmysql.dll. And it seems that path is not proper so it searches in PATH environmental variable. apache/bin will be there in PATH directory. So it is taking the dll from this path. If the dll is not present in that path I think it fails to load and hence fails.
EDIT: Added the solutions which were added in comments
Try rebooting your machine. I had the same issue with mysqlpp library. Path was pointing to mysql bin dir but it still couldnt find libmysql.dll – Daniel (Jan 26 at 6:55)
Apache might be running with credentials different from your own (almost certainly so if you're running it as a service.) Try placing the dirs in the SYSTEM path, not the USER path. – moocha (18 hours ago)