server: Red Hat 4.4.7-18
When i launch php script with cli:
php myscript.php >> my.log
before the output 'echo', there is 2 more lines in the my.log file:
X-Powered-By: PHP/5.6.33 Content-type: text/html; charset=UTF-8
How to prevent this output ?
Tanks a lot and sory for my english.
Related
I've got a bash script which runs 4 commands and redirects to a file. This script works fine when I run it myself from the CLI on my server. It does not work when I let cron run the script.
my file looks something like this:
#!/bin/bash
command > file.csv
command >> file.csv
command >> file.csv
command >> file.csv
I get the expected result when I run it myself but when cron runs it I get this:
X-Powered-By: PHP/7.1.31
Content-type: text/html; charset=UTF-8
X-Powered-By: PHP/7.1.31
Content-type: text/html; charset=UTF-8
X-Powered-By: PHP/7.1.31
Content-type: text/html; charset=UTF-8
X-Powered-By: PHP/7.1.31
Content-type: text/html; charset=UTF-8
I execute the cron job like this:
/usr/bin/php -q /home/user/rest/of/path/script.sh >/dev/null
can someone please help? Driving me mad....
The solution was specifying a PATH property in the bash script.
I echoed the $PATH variable in my shell and copied this into the script and this seemed to solve things.
I tried searching around to find an answer to this but to no avail.
I have a simples PHP script with the below code:
<?php
header("Content-Type: application/json");
echo "Hello";
?>
I then execute the file using the below command:
php -f index.php
and the output is:
Hello
My question is, is it possible to return the header I outputted using PHP, so my expected output would be something like:
Content-Type: application/json
Hello
You can achieve this by using php-cgi without the -f option:
php-cgi index.php
X-Powered-By: PHP/7.3.3
Content-Type: application/json
Hello
I'm using this script to post some date using curl in a post.sh file
#!/bin/sh
var1=`base64 javascript_100.file`
# post it 3 times
for i in `seq 1 3`; do
/usr/bin/curl -i --verbose -d "jobTexterea=$var1" http://my_server_address/target_page.php
done
I don't have any problems executing the post.sh file using my Shell however when i invoke it inside my php script using shell_exec('sh /path_to_post_file/post.sh') I'm getting this error from my var_dump(shell_exec('sh /path_to_post_file/post.sh'));.
Error: () HTTP/1.1 302 Found Date: Sat, 24 Sep 2016 15:14:38 GMT Server: Apache/2.4.23 (Fedora) OpenSSL/1.0.2h-fips PHP/5.6.25 mod_perl/2.0.9 Perl/v5.22.2 X-Powered-By: PHP/5.6.25 Location: http://my_server_ ddress/ Content-Length: 401 Content-Type: text/html; charset=UTF-8 A MySQL error has occurred.
Your Query: INSERT INTO jobsNum_pro_batch (job_batch_id , jobs_in_batch , job_type ) VALUES ( '26' ,'1' ,'JavaScript' )
The code in the post.sh file posts the information to the target_page.php wich puts all the content into different tables in a database. The thing is that no information is being uploaded into the database with running shell_exec('sh /path_to_post_file/post.sh') from a PHP page. However, the command itself runs without errors, I checked it with
<?php
if (shell_exec('sh /path_to_post_file/post.sh')){
echo "<b> shell_exec was executed </b><br>";
var_dump(shell_exec('sh /path_to_post_file/post.sh'));
} else {
echo "<b> shell_exec was not executed </b><br>";
}
?>
I'm getting the message shell_exec was executed
Has anyone an idea what went wrong?
This did the trick! Thanks to #Jean-FrançoisFabre and a small change to his code and problem is gone!
#!/bin/sh
progdir=$(dirname $0)
var1=`base64 $progdir/javascript_100.file`
# post it 3 times
for i in `seq 1 3`; do
/usr/bin/curl -i --verbose -d "jobTexterea=$var1" http://my_server_address/target_page.php
done
I am attempting to backround a php script since it will take more than a minute to complete and I do not want the user to wait.
my exec command is as follows:
exec ('php -f path/to/file.php > path/to/output.log 2>&1 &');
first of all the script in the file didnt do what i programmed it to do however, the output file still recieves this output:
X-Powered-By: PHP/5.6.24
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
Pragma: no-cache
Content-Type: text/html; charset=UTF-8
Link: <https://example.com/wp-json/>;
rel="https://api.w.org/"
Link: <https://example.com/?p=687>; rel=shortlink
....
This output is not at all what my script is supposed to make, it makes no sense to me.
the rest of the output is a html document with differnet links to my website and such.
can anyone clue me into why this is happening and not simply running the script?
BTW
I have used different commands like /usr/bin/php with the same affect
UPDATE
I noticed that after changing the first path/to/file.php paremeter to gibberish i.e.
exec ('php -f asdfjaskldfj > path/to/output.log 2>&1 &');
that the output remains the same, not sure what this means but i believe it to be noteworthy
After must trial and error I found that
usr/bin/php
pointed to a php command that only outputted documentation on my current server, and when I changed it to
usr/bin/php5
it worked. Very hard to find documentation on the linux php command, and I still have yet to find anyone else with the same problem, but it has been resolved nonetheless.
You can run PHP with the -q command line switch. The manual only say:
Quiet-mode. Suppress HTTP header
output (CGI only).
What does that actually mean in practical terms?
This only concerns the PHP interpreter built against the CGI SAPI. This version sends a few basic HTTP headers before any actual output:
X-Powered-By: PHP/5.3.3-1ubuntu9.3
Content-type: text/html
"(echo) What I actually wanted to have"
So basically the -q commandline flag prevents any header() from being written to stdout.
The purpose is to use the php-cgi binary in lieu of the php CLI variant for console scripts. Usually you see following shebang in such scripts to force php-cgi to behave like the -cli version:
#!/usr/bin/php-cgi -qC
As you can see with -q key php suppresses to send headers (added some new lines in the output though to make it more readable):
zerkms#l12 ~ $ cat file.php
<?php
header('Location: http://stackoverflow.com');
echo 42;
zerkms#l12 ~ $ php file.php
Status: 302 Moved Temporarily
X-Powered-By: PHP/5.2.17
Location: http://stackoverflow.com
Content-type: text/html
42
zerkms#l12 ~ $ php -q file.php
42