A perfect solution to the relative path problem under the PHP command line-php Tutorial

Source: Internet
Author: User
A perfect solution to the relative path problem under the PHP command line: PHP Time: October 13, December 18, 2015

Generally, PHP runs as CGI and Apache modules, and PHP rarely runs in CLI. When using include and require in the PHP file under the (CLI) Command Line, you must switch the current working directory before using the relative path. Otherwise, an error is reported and the file cannot be found. Next, let's take a look at the perfect solution to the issue of executing relative paths under the PHP command line (CLI.

$ Cur_dir = dirname (_ FILE _); // Obtain the chdir ($ cur_dir) Directory of the current FILE; // change the current directory to the specified directory. Require (../class/a. php); // introduce the relative path file

In another small detail, when writing a file in PHP for another row, \ r \ n is sometimes invalid. Please check whether \ r \ n is a single quotation mark. double quotation marks must be used here.

In this way, we can use PHP for some scheduled processing when the traffic is small. In fact, in Linux, we can work with the crontab scheduled task. PHP can help us do a lot of things. For example, daily statistics, database backup, log clearing, and some routine maintenance.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.