I've a PHP script that uses cURL to perform certain tasks. At the moment, I have the script running every 10 minutes. This is what I'm running via Windows Task Scheduler.
C:\wamp\bin\php\php5.4.3\php.exe -f C:\wamp\www\autoscripts\index.php
However, for some reason, whenever the argument quoted above is run through the command line, I get the error "Fatal error: Call to undefined function curl_init()". The script works perfectly when I access it via the browser. Is there any reason why PHP isn't able to access the cURL extension via the command line?
Most likely running from command line does not use any ini file that loads the extensions. Open phpinfo() from the browser, copy path to loaded ini file and change your task to:
C:\wamp\bin\php\php5.4.3\php.exe -c "C:\path\to\php.ini" -f C:\wamp\www\autoscripts\index.php
Figured it out. Basically, on WampServer, there are TWO php.ini files that you need to be aware of.
C:\wamp\bin\php\php5.4.3\php.ini
C:\wamp\bin\apache\apache2.2.22\bin\php.ini
Forgot that the command line uses a different ini file than the web server. :(
Related
I'm running a CakePHP project under XAMPP (Apache) on Windows 10 Anniversary Update.
Apache is running under my user account.
The app calls several external processes via shell_exec(): ImageMagick, phantomjs execute as expected.
I also want to call a bash script, that in turn calls ImageMagick under Ubuntu bash (installed separately, via apt-get). I've had to adjust all paths into a form that bash can resolve.
bash /mnt/e/Projects/project-name/website/bin/crop_to_aspect.sh 1 1
/mnt/e/Projects/project-name/website/webroot/images/agent_photo/tmp_ed564289-a6f6-45b7-b9f3-2aec2b8bb3d1.jpg
/mnt/e/Projects/project-name/website/webroot/images/agent_photo/ed564289-a6f6-45b7-b9f3-2aec2b8bb3d1.jpg```
The command fails when called via shell_exec(). The same command, written to CakePHP's log, and then called from a cmd.exe prompt, works perfectly.
Thinking it may have been a path issue, I wrapped the same script in a windows batch file, including the full path to bash. I called the full batch file path, ie:
#echo off
SET aw=%1
SET ah=%2
SET in=%3
SET out=%4
C:\Windows\System32\bash.exe /mnt/e/Projects/project-path/website/bin/crop_to_aspect.sh %aw% %ah% %in% %out%
This script is then called:
E:\Projects\project-path\website\bin\crop_to_aspect.bat 4 3
/mnt/e/Projects/project-path/website/webroot/images/listing_photo/tmp_ed564289-a6f6-45b7-b9f3-2aec2b8bb3d1.jpg
/mnt/e/Projects/project-path/website/webroot/images/listing_photo/ed564289-a6f6-45b7-b9f3-2aec2b8bb3d1.jpg
Once again, the command executes correctly in cmd.exe but does nothing when run via shell_exec() from the PHP script.
Check if a function is not in the list of functions disabled in php.ini (disable_functions) line
I am running a local WAMP on my Windows 7 with a PHP script that executes a windows command as follows:
`exec('"%CD%\files_for_redistribution\ppt2html5.exe" /i:"%CD%\test.ppt" /o:"%CD%\output.html" /title:title /desc:description /author:author /keywords:keywords',$output,$error);`
The command when run from a batch file does the job well but when run from PHP script, gives an error:Presentation opening error: PowerPoint could not open the file.
The intention of the command is to convert PowerPoint to HTML using a third party software called ppt2html5.exe where test.ppt has to be converted to output.html.
I have found lot of blogs discussing about exec function not working properly but nothing really helped me to deal with this error as it runs the command but cannot open the file.
It would be great if somebody could help me with this.
Check if safe mode is on, because that activates escapeshellcmd and some characters are escaped.
Assuming that the string that you are passing to exec(), including percentage signs, routes and parameters are right, your problem may be related to permission of files and user executing apache + php, check that.
Fixed by adding a folder named Desktop inside C:\Windows\System32\config\systemprofile.
Source:http://www.sitepoint.com/forums/showthread.php?956457-Windows-2008-PHP-new-COM%28powerpoint-application%29
I have added this line PATH DEFAULT=${PATH}:~/bin/ to the ~/.pam_environment
This allows me to call ffmpeg from command line without path which is obviously in ~/bin/ dir so everything works fine as long as im ussing command line.
But if try to run the exact same command from php all i get is sh: ffmpeg: not found
And the code is
shell_exec("ffmpeg 2>&1");
So from my very little experiance with linux (in this case Ubuntu to be specific) i guess apache has no access to pam_environment or ~/bin
What can i do to make this work?
look at the output of phpinfo(), it has a section with all environment variables it sees. then look at your webserver configuration, maybe it's sanitizing the environment, or maybe the init script which starts your webserver does it.
and is the account the webserver is running under using PAM at all?
I have a php script that works perfectly on the browser BUT it has this error on windows command line.
I have ssl enabled in php config and from what I gather it works for browser but not command line but I don't understand the difference between these two (neither is windows service I belive). Basicly I don't know what to do about it and I need to run the script from commandline, then create .bat file (in order to start windows scheduler - like cron under linux).
I have windows Xp and Xampp. Please help.
As mentioned in comment above. Php in command line uses different php.ini config.
I have a PHP script that needs to run from command line. One of the function it calls is socket_create.
In php.ini, I have included the following in order to get that function working (see the comment on http://www.php.net/manual/en/sockets.installation.php):
extension=php_sockets.dll
How do I run the script from command line such that it doesn't complain that socket_create is an unknown function? Does PHP CLI actually respect what's in php.ini? I thought it was supposed to, but I do get errors when running it via CLI and no errors when running it via the browser.
UPDATE: by the way, I'm testing this out: https://github.com/nicokaiser/php-websocket. I assume that the server needs to be executed via command line.
A different php.ini file may apply when running php on the CLI rather than as a web server module. You appear to be using Windows, so I'm not sure where this file may be, but it could provide a clue; look for several php.ini files in your disk and see if one of them applies to CLI invocations.