I am using HMVC with codeigntier and try to run a cron job.
I am using this for the cron:
php /home/onlblcm/dev.mytranslator.com/index.php mytranslator cron cronTranslations > aaa.txt 2>&1
When running this from cron job, in aaa.txt file I get
Set-Cookie: ci_session=e56ef3d7d05652937b3269852d8b36eaeebba9a2; expires=Wed, 05-Sep-2018 13:39:26 GMT; Max-Age=7200; path=/; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Refresh:0;url=http/http/user/login
Content-type: text/html; charset=UTF-8
So it's super strange for me.
If I run the exact same command
php /home/onlblcm/dev.mytranslator.com/index.php mytranslator cron cronTranslations > aaa.txt 2>&1
From Putty (ssh) I get what I need. The file runs good. I get the desired output.
So it's the exact same command, but with CRON it fails.
I checked to see in SSH, and I am using user onlblcm
I checked the cron, and it's using the same user: onlblcm
So what can be the problem?
EDIT1:
I added -f in front of the index.php and I now get the error output:
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 284
<p>Backtrace:</p>
<p style="margin-left:10px">
File: /home/onlblcm/dev.mytranslator.com/application/third_party/MX/Loader.php<br />
Line: 173<br />
Function: _ci_load_library </p>
<p style="margin-left:10px">
File: /home/onlblcm/dev.mytranslator.com/application/third_party/MX/Loader.php<br />
Line: 192<br />
Function: library </p>
<p style="margin-left:10px">
File: /home/onlblcm/dev.mytranslator.com/application/third_party/MX/Loader.php<br />
Line: 153<br />
Function: libraries </p>
<p style="margin-left:10px">
File: /home/onlblcm/dev.mytranslator.com/application/third_party/MX/Loader.php<br />
Line: 65<br />
Function: initialize </p>
<p style="margin-left:10px">
File: /home/onlblcm/dev.mytranslator.com/application/modules/admin/controllers/Admin.php<br />
Line: 8<br />
Function: __construct </p>
As you can see, it's going to: /home/onlblcm/dev.mytranslator.com/application/modules/admin/controllers/Admin.php
But that has no sense, since I am not calling my admin controller.
Again, if I call the command from SSH it's working, from CRON is messed up.
EDIT 2:
I added to cron jobs this command:
php -f /home/onlblcm/dev.blasteronline.com/index.php > az.txt 2>&1
I get the exact same thing (error) when calling from Cron Job.
If I call it from SSH I get no output.
if I call from cron, I get the error like above.
EDIT 3:
I now managed to get the same error when using Putty/sssh.
If I run the command (ssh) with
php ....
It runs good
If I run the command (ssh) with:
/usr/bin/php
I get the same error like in cron.
With cron I tested with php ... and /usr/bin/php ... and I get the same error.
So somehow php is different than /usr/bin/php .
But I outputed the phpinfo and it's the same version.
When I use php info (via ssh) and use php I get a 32KB file with information (not html formated). When I use /usr/bin/php calling a file with php info, I get a file with 94K info (it is html formatted).
What is happening? Any ideas?
EDIT 3: SOLVED
It seems somehow the cron was calling a different PHP (although same version).
From Putty (ssh) I did a "whereis php"
I found 2 folder: /usr/bin/php AND /usr/local/bin/php
It seems calling simple php or /usr/bin/php FAILED the cron
When calling the cron with /usr/local/bin/php IT WORKS
Thanks
Related
Hello and thanks in advance,
I am using Laravel 5 hosted on Godaddy. I am trying to get a cron job to run but I keep getting this message:
Status: 404 Not Found
X-Powered-By: PHP/7.1.11
Content-type: text/html; charset=UTF-8
No input file specified.
I haven't done a cron myself in Laravel before and I decided to follow this tutorial https://scotch.io/#Kidalikevin/how-to-set-up-cron-job-in-laravel
Everything works fine when I run php artisan DeleteInActiveUsers:deleteusers but the Cron doesn't.
Below are the commands I have tried in the Cron, the file name I created based on the tut is called DumpZohoContacts.php.
Note: I have added /usr/bin/php & -q but it still doesn't work I also ran app_path(); to see my app path and check that. And the code is not the issue since it runs fine by itself
Cron Commands:
php /home/[hidden]/public_html/rms/artisan schedule:run
php /home/[hidden]/public_html/artisan schedule:run
php /home/[hidden]/public_html/rms/artisan zohoDumpToDb:dumpContacts
php /home/[hidden]/public_html/artisan zohoDumpToDb:dumpContacts
php /home/[hidden]/public_html/rms/app/Console/Commands/artisan schedule:run
php /home/[hidden]/public_html/rms/app/Console/Commands/artisan zohoDumpToDb:dumpContacts
php /home/[hidden]/public_html/rms/app/Console/Commands/DumpZohoContacts.php
From my Email, I used to get this warning. Iff you have entered an incorrect command
PHP Warning: Module 'magickwand' already loaded in Unknown on line 0
Status: 404 Not Found
X-Powered-By: PHP/5.6.37
Content-type: text/html; charset=UTF-8
No input file specified.
If you are about to schedule the command as once a day (i.e., 00:00) the same time should be reflected in a $schedule->command(); object
In Kernel.php you should specify
/**
* Define the application's command schedule.
*
* #param \Illuminate\Console\Scheduling\Schedule $schedule
* #return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('SyncAPIOrders:orders')
->timezone('Asia/Kolkata')
->dailyAt('00:00');
}
You should add the command from the cPanel server as
/usr/local/bin/php /home/xyz/public_html/artisan schedule:run 1>> /home/xyz/public_html/log_laravel 2>&1
This will keep all the logs in /home/xyz/public_html/log_laravel
Running scheduled command: '/opt/cpanel/ea-php71/root/usr/bin/php' 'artisan' SyncAPIOrders:orders > '/dev/null' 2>&1
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.
I am using a godaddy host. I already set the cron job command in the host php /home/site/laravel/artisan schedule:run
But the problem its returning this error for everytime it runs: [ErrorException]
Invalid argument supplied for foreach()
X-Powered-By: PHP/5.5.30
Content-type: text/html
Also it runs if i use the same artisan command in the ssh
Ok. I found the answer i had to use the command with the full path to the php like this: /usr/local/bin/php /home/mysitename/laravel/artisan schedule:run
Im using an ajax call to execute "shell_exec" on the server (centos).
The line that im executing is the following
echo shell_exec("php -q /websockets/timedactions.php");
This is the server response:
X-Powered-By: PHP/5.5.16
Access-Control-Allow-Origin: http://myIpAddress
Access-Control-Allow-Credentials: true
Content-type: text/html
0
After running this command it seems that the process that it supposed to activate is not running.
Calling the same command on shell with root access
php -q /websockets/timedactions.php
works perfectly.
How can i make the script work using shell_exec ?
There can be errors, while the command is executed. You can redirect STDERR to STDOUT, to see if there are any, like this(Sample 3.5).
echo shell_exec("php -q /websockets/timedactions.php 2>&1");
Also there could be something preventing shell_exec from printing (link).