I have a php script that connects to a database to run a query. This works fine when running the script by browsing to it. The problem I have is when I use the Task Scheduler within the Synology server's control panel. For some reason I am getting the following error:
PHP Fatal error: Call to undefined function mysqli_connect() in /volume1/web/bimotech/check_ip.php on line 13
As mentioned, this works fine when running from the browser but not when scheduled.
Any ideas?
Thanks,
John
It sounds as though the PHP you're running was built without mysqli, or perhaps mysqli is not loaded. Can you run a phpinfo(); and make sure you have mysqli?
Bear in mind that the PHP you use in a CRON job can be different from the PHP that gets run by Apache when your web page executes.
You have to define the full path of your php, synology maybe using different version of php.
For example your php executable is installed on /usr/bin/php
you have to do something like
/usr/bin/php /path/to/script.php
Related
I have a PHP script I'm trying to execute via the command line using the exec() function and I'm getting errors saying PHP can't locate the various classes that are part of the PHP ImageMagick extension (PECL is what I'm using) but it is installed correctly and works fine when running other scripts that use it via the browser.
I'm executing my code this way to create multiple instances and essentially cause parallel processing by allowing Linux to optimize the various processes across my CPU cores on its own. It works great for all the other things I use it for, but not in this situation.
Do I need to change how I installed Imagemagick?
PECL Extension was missing from CLI INI File. Apparently there are two of those files, on for browser execution and another for command line interface.
I'm running Parallels Plesk on a Hostgator windows server. I am trying to set up a 'Scheduled Task' ie cron job running every 5 minutes that simply loads a webpage, nothing more. This is my current setup:
Unfortunately, nothing seems to work. I was ideally looking for something like wget "myurl" to keep it simple, but it doesn't look like it takes commands, only executables. I created a php script with a file_get_contents to load the page, and used the PHP installation as the executable passing the script location as the argument, but this doesn't work either. What am I doing wrong? What I am trying to achieve is so simple.
Looks like it happens because of spaces in path C:\Program Files (x86)\
Try to quoting full path to PHP binary.
My server was running PHP scripts perfectly up until now. I don't know what happen to my server, but the PHP scripts are not running, instead, it is automatically commented by the server. When I uploaded my php script to show PHPINFO, this is what gives me back:
<!--?php
// Show all information, defaults to INFO_ALL
phpinfo();
?-->
if you view the source code, you would see that my php scripts are commented. What should I do to get my PHP scripts running?
Thanks for helping.
Does the same thing occur if you execute the script from the PHP command line interface?
Seems like something external is explicitly disabling PHP execution either at the web server level or software level. Are you using some type of framework around PHP which my be limiting PHP execution, ie CakePHP, joomla etc?
I am wondering if a PHP script can be executed from a shell command line.
Does a script executed from shell have the exact functionality if executed from the browser? or is there a difference in coding.
Is it better to run a script from shell for performance and also is it better to run it from windows or unix/linux
I am asking all these questions because, I am suppose to develop a PHP script that can fetch some data from http headers of some urls listed in a MySQL db and then store the data in the database.
Can you guys point me to the right direction please, Do I need ubuntu, or is there a shell that can run php from windows? all I have at the moment installed is WAMP, which has mysql, php and apache server.
I am sorry for being a novice.
thanks for your kind help
I am wondering if a PHP script can be executed from a shell command line.
Yes
Does a script executed from shell have the exact functionality if executed from the browser? or is there a difference in coding.
It won't have $_REQUEST and friends populated, and $_SERVER won't have server information in it.
Is it better to run a script from shell for performance
Maybe. It avoids the overhead of runnning a webserver. It stops you having cached versions in memory for faster re-execution.
and also is it better to run it from windows or unix/linux
Benchmark it.
I am asking all these questions because, I am suppose to develop a PHP script that can fetch some data from http headers of some urls listed in a MySQL db and then store the data in the database.
There doesn't seem to be any need to involve a web server for that.
Can you guys point me to the right direction please, Do I need ubuntu, or is there a shell that can run php from windows?
The standard Windows shell can.
all I have at the moment installed is WAMP, which has mysql, php and apache server.
You'll need the command line version of PHP. I've no idea if WAMP includes it or not.
I am wondering if a PHP script can be executed from a shell command line.
It's possible either by executing:
$ php -f your_script.php
Or by inserting #/usr/bin/env php into the first line of the script and by making it executable.
$ head -n 1 your_sript.php
#/usr/bin/env php
$ chmod +x your_script.php
$ ./your_script.php
Note: this example only works on UNIX systems.
Does a script executed from shell have the exact functionality if executed from the browser? or is there a difference in coding.
You can use the same Syntax/Functions etc. The only difference is that there are command line arguments in $argv and some other values in the $_SERVER variable.
Is it better to run a script from shell for performance and also is it better to run it from windows or unix/linux.
That doesn't really matter. For your usecase you don't really need a webserver, and a full featured GUI. The advantage of having a command line tool is, you can combine your program with other program available like grep etc.
Can you guys point me to the right direction please, Do I need ubuntu, or is there a shell that can run php from windows?
You don't need ubuntu, you can also execute a shell script from windows. The PHP executable is located in the %PATH%. This question will help you in order to do this: https://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them
Then simply open cmd.exe and execute a script using php -f your_script.php
Yes, PHP can be run from command line.
No, there aren't any differences in coding.
The only difference is that it's not Apache running the script, but the user you are currently logged in as. That could mean different privileges on certain maps and folders.
Yes you can execute PHP from the command line using:
/path/to/php.exe /path/to/script.php
The main difference is that it doesn't run through Apache, so you won't have things that rely on it (like some $_SERVER data).
Also it won't be subject to timeouts on the command line, unless you have a PHP limit set.
Take a look at http://php.net/manual/en/features.commandline.php for more info.
I have a (possibly dumb) question.
I have a script made in php, constructed for cli usage. Works fine when I run it from the command line, no problem there. The problem is that the site I'm working on has ssh restrictions on the hosting server and I cannot ssh there to run it. Hence my question: how can I run the script from another php that is web-accessible? Already tried with exec(), system(), etc.
The main problem is that I need he $_SERVER['SHELL'] variable set, and when the call is comming from a web browser of course php doesn't set it.
Any ideeas will be greatly apreciated, thanx.
There are many possibilities why exec() and related function calls are not working for you.
Your webhost does not have PHP-CLI installed. Just a webserver module
You need to use the full path to the php binary for lack of a decent shell environment. E.g. /usr/bin/php <script> instead of php <script>.
Your webhost has installed PHP-CLI on a non-standard path (e.g. /usr/local/bin/php, or /opt/php5/php)
The webserver user does not have rights to access the php binary
Et cetera..
maybe update the php script to be both an include and a cli script.
use
__FILE__
to check if it's a file, then read the params. otherwise do nothing.
and as an include just call the function you want directly.