I've problem with cron job.. I set cron job to running a file every five minutes, but thats not work... Cron job not running file, the code:
<?php
set_time_limit(1000000000000000);
include $_SERVER['DOCUMENT_ROOT'].'/includes/connect.php';
mysql_connect('localhost', 'root', '') or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$getinfo = mysql_query("SELECT * FROM something WHERE game_id = '2'") or die(mysql_error());
while($servers[] = mysql_fetch_assoc($getinfo)){
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
</head>
<body>
</body>
</html>
Thanks all who try to help...
Scripts rely on a special syntax to pick the interpreter to use. If you point the crontab entry directly at the file there is no way to determine the interpreter to use. If you look in any shell script you'll see a first line like:
#!/bin/sh
This points to the interpreter for the script. Point it at your php binary or call the script using
php /path/to/script.php
You also need to ensure the file has the executable permission set:
chmod +x /path/to/script.php
I found this page by googling "php run as script" which says roughly the same thing but with more details:
http://blog.johan-mares.be/ict/php/running-php-shell-scripts/
Related
when I tried to curl some pages.
curl http://test.com
I can get like following result
<html>
<body>
<div>
<dl>
<dd> 10 times </dd>
</dl>
</div>
</body>
</html>
my desired result is like simply 10 times..
Are there any good way to achieve this ?
If someone has opinion please let me know
Thanks
If you are are unable to use a html parser for what ever reason, for your given simple html example, you could use:
curl http://test.com | sed -rn 's#(^.*<dd>)(.*)(</dd>)#\2#p'
Redirect the output of the curl command into sed and enable regular expression interpretation with -r or -E. Split the lines into three sections and substitute the line for the second section only, printing the result.
So I am a novice at Web development and I am trying to create a website and am using WAMP to test out my PHP code and such. The issue I'm running into is that when I change my file, and try to refresh my localhost page on my browser, it gives me a file not found error. When I close out the localhost page and reopen it, the page that I changed appears properly and is updated properly.
I was just wondering whether there is an issue with my WAMP or whether having to open a new localhost page is necessary every time a file is updated?
I would ensure the file path is correct, double check that you are dev-ing from the same folder that you are viewing in localhost. Also what worked for me is doing a browser cache refresh which is different from a simple refresh. http://refreshyourcache.com/en/cache/
Windows: ctrl + F5
Mac/Apple: Apple + R or command + R
Linux: F5
<link rel="stylesheet" href="http://localhost/CI-social-media/css/registration_form.css?v=<?php echo time(); ?>">
<script language="javascript" src="http://localhost/CI-social-media/js/registration_form.js?v=<?php echo time(); ?>"></script>
<link rel="stylesheet" href="http://localhost/CI-social-media/css/registration_form.css?v=<?php echo time(); ?>">
<script language="javascript" src="http://localhost/CI-social-media/js/registration_form.js?v=<?php echo time(); ?>"></script>
use this & solved problem
just add ?v=<?php echo time(); ?> after href="('path/url') then after "
just add ?v=<?php echo time(); ?> after src="('path/url') then after "
<link rel="stylesheet" href="http://localhost/CI-social-media/css/registration_form.css?v=<?php echo time(); ?>">
<script language="javascript" src="http://localhost/CI-social-media/js/registration_form.js?v=<?php echo time(); ?>"></script>
I'm unable to execute php scripts from command line. I have the following simple code in a file named test.php:
#!/usr/bin/php
print password_hash("rasmuslerdorf", PASSWORD_DEFAULT)."\n";
On executing, I get this:
#./test.php
print password_hash("rasmuslerdorf", PASSWORD_DEFAULT)."\n";
About my environment, it's a Debian 7 x64 server.
#which -a php
/usr/bin/php
#`which php` -v
PHP 5.6.9-0+deb8u1 (cli) (built: Jun 5 2015 11:03:27)
What could be wrong with my installation?
You need to encapsulate your PHP code with the proper tags else it will be interpreted as plain text. Modify your PHP file to the following:
<?php
print password_hash("rasmuslerdorf",PASSWORD_DEFAULT)."\n";
?>
I downloaded a Bash script from Internet.
However, when I try to run it, it fails because of the && commands and prints the following error message:
No command 'amp' found
What is amp ?
What is gt ?
What do they do?
I suspect this has undergone an HTML entity translation. You want to reverse this e.g.
& becomes &
and
> becomes >
So (for example)
cd /dir && ls > filename
would become
cd /dir && ls > filename
in other word, & is the character reference for "An ampersand". While gt is simply we call it as (greater than).
& and > are html escape codes for & and > respectively.
Either you have downloaded a script that has been htmlized, or you've accidentally downloaded a webpage with the script on.
Check the top line of the file. if it starts with something like #!/usr/bin/bash then it's the former and you just need to reverse the changes. If it has something like a <html> tag as the start, then you've downloaded the webpage - go back to where you got it and look for something like a 'raw' link
I've spent days still can't figure out this.
I have following file structure under public_html:
cron_jobs/file.php contains - > include('../base/basefile.php')
base/basefile.php contains - > include('baseSubFile.php')
when I run
/pathtophp/php -f ~/public_html/cron_jobs/file.php
it works ok but when I copy the same command to cron in cpanel, I get error saying
'basesubfile.php' can't be found
Please help.
Cron won't run from the same directory as your php file is in, so you'll need to change to it first:
cd /home/user/public_html/cron_jobs/ && /pathtophp/php -f file.php
I recommend the full path versus ~ when dealing with cron scripts to avoid confusion
You should used
include dirname( __FILE__ ) . '/../base/basefile.php';
and
include dirname( __FILE__ ) . '/baseSubFile.php';
The function dirname returns parent directory's path
Simply put this at the top of your PHP script:
chdir(dirname(__FILE__));