11

I m trying to run php file from the command fine. here files are not included. Whrn I run php script from the browser its works perfect but when I run it from cmd then its giving error for that included file

PHP code

require("include/config.php");
include_once('include/classes/dbclass.php');
include_once('include/classes/send_emails.php');

Here suppose I put the code of dbclass.php file into main one and removed include_once('include/classes/dbclass.php'); line than there is no problem. So how to write include path or set include file when we used cmd to run php script

1
  • Please provide your directory structure.. Commented Jan 7, 2015 at 9:05

3 Answers 3

13

Your setup may have different php.ini option files for cmdline and web use, you can either add the right include_path to the cmdline ini file (/etc/php5/cli/php.ini in my case), or pass it as a command line parameter:

php -d include_path=... script.php
Sign up to request clarification or add additional context in comments.

1 Comment

How to add multiple include paths? Semicolon separated?
9

I like doing:

require dirname(__FILE__) . '/../include/file.php';

That way all includes and requires are relative to the local file.

Also, require, etc are not functions. You should not use parenthesis.

Comments

0

You can also change directory ("cd") in the cmd window to the directory of the file you are running before you run it. Then it should get the correct paths.

1 Comment

yep: cd /var/mydirectory && runmycron

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.