Hi i was trying to emulate a post created from javascript in a site with curl from a php script but it seems some variables have the same name and they get overwritten, is there a way to run the script itself from command promt, assuming i make the necessary changes to it?
Well ... you can always install NodeJS and then just write in terminal: node <filename>
Related
I have a directory that when accessed through the terminal, I run the command 'make' then 'make install' which subsequently builds a dictionary file. I want to automate this process, which will kick off when the user selects a button on the interface.
Using PHP in my web app I want to navigate to the directory which I have done so here:
chdir('../DictionaryFolder');
Then, I thought this PHP command would run the make and make install:
exec(make);
exec(make install);
But this does nothing.
Any help will be much appreciated!
You need to write the command like the following,
<?php
$output = shell_exec('make;make install;');
echo "<pre>$output</pre>";
?>
Shell exec will do the trick by calling $output via pre tag.
Exec() try to execute PHP like eval() in JS, shel_exec execute commande like you with CLI
I need your help here.
I wrote one PERL script for PHP application which needs to be run for every 5 mins.
This script will call PHP program, which will fetch data from MySQL DB and will generate a excel report and will mail those reports to specific users.
Every thing seems to be fine when I ran this script manually with the command (perl reports.pl).
But when I set this Perl in a cron tab, nothing works and reports are not getting generated.
Details: perl script path /opt/app/deweb/web/EDI/Microsoft/reports.pl
this script will call PHP program (/opt/app/deweb/web/EDI/Microsoft/reports.php)
content of script
#!/usr/local/bin/perl
use Net::FTP;
use File::Copy;
use POSIX;
#errorreport = `php /opt/app/deweb/web/EDI/Microsoft/reports.php`;
print "#errorreport\n";
exit;
It is working perfectly when running Manually using command - perl reports.pl
No results, when set in CRON:
*/5 7-19 * * * /usr/local/bin/perl /opt/app/deweb/web/EDI/Microsoft/reports.pl
Please note that this crontab is under super user account named webserv and my login is having access to edit under this super user account.
I'm editing this cron tab using command :: sudo -u webserv crontab -e
I would check the following:
Does it run using sudo -u webserv perl reports.pl? If not, fix the problem for the webserv user (permissions or whatever) and it should work via cron too.
Does which perl using your login give you /usr/local/bin/perl? If not, change the path to Perl in crontab to what you got in which perl to fix the problem.
I found myself to be in the same situtation. After trying to find out the reason, I am almost sure about the reason this happens. Crontab does not have the same environment variables as you when running the script. You must be sure about paths. Try for example run your script like /perl-path /path-to-perl-script/script.pl outside the parent directory of the script and I am almost sure that your programm will not find some files. And as you call one php script from the perl script, it's possible to have the same problem with paths to your php script too.
So the solution is to use absolute paths and no relative.
Also at your perl script don't use php but /full-path-to-php for example:
#errorreport = /usr/bin/php /opt/app/deweb/web/EDI/Microsoft/reports.php;
I want to run a PHP script every 15 minutes using either CURL or WGET.
This PHP file is in a local folder:
/home/x/cron.php
How would I run this using CURL/WGET?
It doesn't work when I try to run
curl /home/x/cron.php
Thank you!
CURL and WGET are more adecuate for URLs like http://myhost.com/cron.php
When the script is offline, you would better run it using php CLI:
Ex:
php -q cron.php
Just do something like this:
/usr/bin/php /home/x/cron.php
cURL/wget is for HTTP actions. If your PHP script is on the same system, you don't want to load it over HTTP. (You can, of course, if it is accessible over HTTP, but I don't think that is what you want.) Just call it directly.
Alternatively, you can set the execute permission on your script and throw in a shebang line for PHP:
#!/usr/bin/php
Then, just put your PHP script in crontab directly.
If you're using CURL or WGET, I believe you'll need to pass in the path as a URL. If you want to run the php script on the command line, you'll need to use the the php CLI
I am using GIT on my server and I am trying to get a PHP file to be executed each time I update my repository. I'm trying to use my post-update hook to achieve this.
this is the code I tried:
#!/bin/sh
echo
echo "**** Pulling changes into Prime [Hub's post-update hook]"
echo
cd $HOME/www || exit
unset GIT_DIR
git pull hub master
exec git-update-server-info
php /path/to/directory/file.php
I can't seem to get the PHP to execute. Anyone able to shine any light on this?
exec never returns. Anything you put after the exec call is dead code.
Remove the exec, or place it before your php line if that's the last thing that needs to be done. (And after doing error checking if necessary obviously.)
So for instance
...
git-update-server-info
exec php /path/to/directory/file.php
Or just simply
...
git-update-server-info
php /path/to/directory/file.php
(or move the statements around if your php script can be called before the git command.)
I wrote a script to parse some data from a website using cURL and it works fine when I run it in my browser, however when I want to run it in the command line I get the error "call to undefined function curl_init()". Do php scripts run under different settings from the command line?
This is happening because you are simply trying to call a PHP function from bash. If you have curl installed in your linux environment then the command should simply be curl [-options] [url]. The simplest of them being something like:
$ curl http://someurl.com/path/to/xmlfile.xml
You can test for this from the command line by tying "$ which curl" (without the quotes of course). That will give you the path to where it is stored in case you have to use the full path. (e.g. /usr/bin/curl [-options] [url]).
EDIT:
after having re-read your question I realized that I dumbly missed the fact that you said you were trying to run the PHP script from the command line and not curl itself. And now I, too, am stumped by your problem. Sorry!