i have the functionality to generate XML file on each day using php.
This works fine in the browser.but it doesn't work in the cron job.
The cron give me error for the required once and Fatal error.And it stops the execution of my cron job.
the included file is also including other files.
the error which i am getting is like,
Warning: require_once(/common/configs/config_local.inc.php) [function.require-once]: failed to open stream: No such file or directory in /home/wwwsite/public_html/sitename/common/configs/config.inc.php on line 281
Fatal error: require_once() [function.require]: Failed opening required '/common/configs/config_local.inc.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/wwwsite/public_html/sitename/common/configs/config.inc.php on line 281
any one having solution to this issue?
It's telling you it can't find '/common/configs/...' note the absolute path there with the first character being a '/'.
You can either make it a relative path from where you are defining it, or put the prefix in there as well ('/home/wwwsite/public_html/sitename/'), maybe with a variable ($sitebase ='/home/wwwsite/public_html/sitename/';) and prefix the include filename with it.
The reason it is working on a website, but not on the command line could be one of a few ways. Most obvious is that the php.ini include_path for the CLI (command line interface) doesn't include the '.' for checking from the current directory. There's also a good reason it doesn't have it by default. The other way is maybe your code puts the ..../sitename/ directory into the include_path - or otherwise sets up the files to be included automatically.
i have got the solution,
curl yoursitename/yourfilename.php > /dev/null 2>&1
This has run my cron job as i have set without any error
Related
When creating a scheduled task to run a php script in Plesk Onyx on windows it results in an error.
However when i run the same script in the browser it works without any issues.
I have been looking for the permission settings in the webroot and set them to allow access to all user groups on the server.
The error i get is the following:
Warning: require(\pcp2\inc\db_config.php): failed to open stream: No such file or directory in D:\www\domain\pcp2\conversion\addBooking.php on line 5
Fatal error: require(): Failed opening required '\pcp2\inc\db_config.php' (include_path='.;.\includes;.\pear') in D:\www\domain\pcp2\conversion\addBooking.php on line 5
Line 5 contains the following info:
require($_SERVER['DOCUMENT_ROOT']."\pcp2\inc\db_config.php");
It's failing becasue $_SERVER['DOCUMENT_ROOT'] is a value provided by the web server, and is thus undefined when run without a web server (i.e., from the command line.) You'll need to provide an alternative mechanism to set the base directory.
You might use relative paths:
require("pcp2\inc\db_config.php");
Or absolute paths based on the magic constant __DIR__. (This assumes the script doing the require'ing is in the document root directory.)
require(__DIR__."\pcp2\inc\db_config.php");
Ideally however, you're better off using PSR-4 namespacing with an autoloader.
I have recently been trying to add PHPMailer script to my site, following the accepted answer from here:
Send attachments with PHP Mail()?
I have never used a require statment before so I assume I must be doing it wrong, currently testing on my local host version of the site. I have downloaded the entire zip of git (unzipped it) and moved it to the dir my scripts are in.
In my script I added the following line:
require_once(__DIR__.'/PHPMailer-master/class.phpmailer.php');
Which to my understanding was all I needed to do to use it. However I get this error:
Warning:
require_once(C:\xampp\htdocs\Website\PHPMailer-master\class.phpmailer.php):
failed to open stream: No such file or directory in
C:\xampp\htdocs\Website\include\mailer.php on line 10
Fatal error: require_once(): Failed opening required
'C:\xampp\htdocs\Website\PHPMailer-master\class.phpmailer.php'
(include_path='C:\xampp\php\PEAR') in
C:\xampp\htdocs\Website\include\mailer.php on line 10
Any ideas what is causing this error? Am running PHP 5.6.21 if this is relevant.
Try to use the full path to the file, using realpath() - http://php.net/realpath, and use dirname(__FILE__) to get your current directory:
So I have a script that updates all currency rates for my webshop.
I am trying to have it run using a cronjob but when it's executed through a cronjob I get this error:
PHP Warning: require(.../.../core/dbcon.php): failed to open stream: No such file or directory in /var/www/domain.com/wholesale/system/labs/cur.php on line 2
PHP Fatal error: require(): Failed opening required '.../.../core/dbcon.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/domain.com/wholesale/system/labs/cur.php on line 2
I've also tried using the full link to include it but that seems to not work when running it manually and will also not work in cronjobs.
In the php file itself this is what I use to include it:
require(".../.../core/dbcon.php");
And when I manually run it, it returns all the currencies right, and updates them in the database.
How would I correctly require the file so it can execute using a cronjob and manually as well.
Try require("./../../core/dbcon.php");
or use absolute paths.
UPDATE
Answer has been updated - see comments below for more info.
All,
I have the following files:
builder.php
Oauth.php
twitteroauth.php
Within my builder.php page I have the following code:
require_once('twitteroauth.php');
Then in my twitteroauth.php page I have the following code:
require_once('OAuth.php');
All of these files are in the following path: wp-content/themes/alyeska/framework/frontend/functions
I'm testing this on my localhost and it works fine. However, when I upload all of these files to my webserver I get the following error message:
Warning: require_once(OAuth.php) [function.require-once]: failed to open stream: No such file or directory in /home/arokyne/website.com/wp-content/themes/alyeska/framework/frontend/functions/twitteroauth.php on line 10
Fatal error: require_once() [function.require]: Failed opening required 'OAuth.php' (include_path='.:/usr/local/lib/php:/usr/local/php5/lib/pear') in /home/arokyne/website.com/wp-content/themes/alyeska/framework/frontend/functions/twitteroauth.php on line 10
I'm not sure why I'm getting these errors since it works on my localhost. Can anyone point me in the right direction on how to fix this issue?
Thanks!
Two things jump to mind- make certain your path is correct, including the case sensitivity; also, make certain that the permissions on the file allow for the php server to read the file. A 644 mode should be sufficient, I believe; but, worst case, a 755 would definitely work.
And finally you may want to check whether your include path is correct.
Here is the first error:
Warning: require(/hb/includes/constants.php) [function.require]: failed to open stream: No such file or directory in C:\wamp2\www\hb\includes\connection.php on line 2
And the second error that immediately follows:
Fatal error: require() [function.require]: Failed opening required '/hb/includes/constants.php' (include_path='.;C:\php\pear') in C:\wamp2\www\hb\includes\connection.php on line 2
Here is the line that it doesn't like:
require("/hb/includes/constants.php");
I did install a new version of WAMP, but I know the directories/files are fine and the code worked previously and on another server. It seems like none of my require()'s are working anymore. I tried looking around and some suggested to others that they edit their php.ini, but I don't know what directory I would point to - if you can't tell I'm pretty noobish regarding all things server related.
Any help is appreciated.
First of all, are your really -- really ! -- sure that the file /hb/includes/constants.php, that your are trying to include, exists ?
Considering that the path you requested begins with a /, it looks like you're using an absolute path... that looks like an UNIX path, but you are on a Windows server...
If it exists, and PHP still cannot include it, check :
that it is readable by your webserver (including the directories) -- I'm thinking about UNIX permissions
that there is no open_basedir restriction that would prevent PHP from accessing those files.
BTW, having a warning and a fatal error is the behavior that's to be expected when using require : the warning is normal (it comes from include) ; and the fatal error is the difference between include and require.