Getting Undefined index: REQUEST_URI - When Run Artisan Commands in Laravel - php

I keep getting the error below every time I try to run an artisan command on Laravel, I'm on the project directory.
For example, I run this command:
php artisan make:migration create_stats_table
And I get this error:
[ErrorException]
Undefined index: REQUEST_URI
No matter what command I run, I get the same error, even php artisan --version returns this error. How can I solve this problem?

Your code expects to have this index, but you're running PHP in CLI mode.
REQUEST_URI variable of $_SERVER superglobal is only available if you're reaching script by browser.

As mentioned already this variable doesn't exist if you run by the CLI. If you can't get around the issue and avoid using it a work around is to use isset()
if (isset($_SERVER['REQUEST_URI'])){
...
}

Related

run python3 scritp using php webpage [/usr/bin/python3: symbol lookup error: /usr/bin/python3: undefined symbol: XML_SetHashSalt ]

I want to run my python3 script using php webpage i used shell_exec() for that and it work fine with commands ex- ls pwd.
my python script just create a .csv file with the current date.
when i run my python3 script using (ubuntu) terminal/ vs code its work fine.
But when i try to run python3 test.py as a command its throw (xampp is running my script using user daemon)
error
[/usr/bin/python3: symbol lookup error: /usr/bin/python3: undefined symbol: XML_SetHashSalt ]
xampp is running my script using user daemon
i tried to give proper permission to the user daemon

How to pass bash script variable value in PHP command (CLI)

I need help in passing the Linux bash-script variable to execute the PHP CLI command.
I am working on the bash-script that executes PHP CLI command that gets input variable from the bash-script like folder-path to include a file for accessing a class of the PHP file.
But what happens while executing the bash-script is that the variable passed to the PHP CLI-command act as a variable for PHP.
Below is the sample-code my script
file="$folderpath"somefile.php
mage_version=$(php -r 'include "$file";print_r(Mage::getVersionInfo());')
Below is the error I am getting
PHP Notice: Undefined variable: file in Command line code on line 1
PHP Warning: include(): Filename cannot be empty in Command line code on line 1
Bash needs double (") quotes to parse variable, otherwise they will stay $var and so php will read them;
file="$folderpath"somefile.php
mage_version=$(php -r "include \"${file}\";print_r(Mage::getVersionInfo());")
More inline bash info
If you need a multi line solution, you can do something like: Run PHP function inside Bash (and keep the return in a bash variable)
php_cwd=`/usr/bin/php << 'EOF'
<?php echo getcwd(); ?>
EOF`
echo "$php_cwd" # Or do something else with it

Why is $this->argument() Showing the Name and the Value?

In Laravel, I am making a console command. Per the docs, you should be able to get the value of the argument using $this->argument():
$userId = $this->argument('user');
I have an argument that is an integer 1. However, $this->argument('some_name') is returning a string such as some_name=1, instead of simply 1
Is there a setting or something that I missed?
Arguments don't get named, unlike options. For example:
$ php artisan command argument1 argument2 argument3
$ php artisan command --option1=foo --option2=bar
So, I'd either change the definition of your argument to an option so that you can run:
$ php artisan command --some_name=1
Or, you can keep using this as an argument and run:
$ php artisan command 1
Note: artisan and command in the above examples are arguments of the php executable.

Rscript behaving differently when run from commandline and from PHP exec

Hi I'm running an Rscript with PHP exec and it is behaving strangely.......It launches R but throws an error at the following line:-
filein = filein[,c("id","bank","trans_date","description","description_2",
"description_3","description_4","description_5" ,"type",
"debit","credit","statement_balance", "cleared_balance",
"debit_int_rate","credit_int_rate","category")]
This simple rearranges the columns in a data-set.
It throws the following error:-
Error in
[.data.frame`(filein, , c("id", "bank", "trans_date", "description",
: undefined columns selected
However I run the same script from command-line it runs without any error.
(I'm running the Rscript on a ubuntu 14.04 machine with PHP5......also when I run the same script on a windows machine from PHP it also runs perfectly)
Anybody have any ideas why this is?
Thanks for all of your help....So it wasn't a permissions issue(I had fixed those previously).......the issue was:----The command passed to commandline by PHP exec was
sudo /Rscript /home/xin/Documents/ClassificationApp/ClassificationAllInOne.R "http://localhost/categorisation/public/classification/data/1423746975.json"
However the argument that was received by R was "localhost/categorisation/public/1423746975.json2";
For some reason the Ubuntu/PHP combination added a 2 to the end of the argument string....I added a line in ClassificationAllInOne.R to strip the 2 and it worked perfectly

Calling git from PHP: Broken pipe error

I have the following PHP script:
#!/usr/bin/php
<?php
echo shell_exec(
"/usr/bin/git clone --bare ".
"/home/dave/create_project/template_project ".
"/home/dave/create_project/my_test_project.git"
);
About 7 in 10 times that I run it, git gives the following error:
find: write error: Broken pipe
This error never occurs if I run the equivalent command directly from the shell.
I have already tried:
using other PHP execution functions: exec, system, popen;
passing the whole command as an argument to bash, i.e., exec('bash -c '.$cmd);
Does anyone have any idea what might be going on?
It may depend on your exact platform, but findutils has been known to throw that kind of error message before.
On Fedora, that rpm package version 4.2.33-2.fc9 fixed the issue.
Does PHP throw any errors? Maybe max_execution_time is too low? Mu guess PHP app exites prematurely.

Categories