What happens to the redirect in PHP files executed in Linux-crontab?

Source: Internet
Author: User
There are index.php files, which contain code:

header("Location: /from_index.php"); # 重定向(from_index.php的文件位置在:/www/)

To join a timed task using CRONTAB-E:

*/5 9-23 * * * sleep 50 && php /www/index.php # php脚本的绝对路径

Will the code in the from_index.php be executed in such a structure?

I learned that if you write:

*/5 9-23 * * * sleep 50 && curl -L -e '; auto' http://127.0.0.1/index.php # http访问

Is able to execute the code in the from_index.php. But is it not efficient to use PHP commands?

Reply content:

There are index.php files, which contain code:

header("Location: /from_index.php"); # 重定向(from_index.php的文件位置在:/www/)

To join a timed task using CRONTAB-E:

*/5 9-23 * * * sleep 50 && php /www/index.php # php脚本的绝对路径

Will the code in the from_index.php be executed in such a structure?

I learned that if you write:

*/5 9-23 * * * sleep 50 && curl -L -e '; auto' http://127.0.0.1/index.php # http访问

Is able to execute the code in the from_index.php. But is it not efficient to use PHP commands?

Execution of PHP
1.cli way, directly with PHP script execution

php  index.php

2. Through the server request CGI mode

curl -L http://127.0.0.1/index.php

The header function jumps, is the server responds to curl (the equivalent of a browser) to redirect, and then re-request the server
So the Php/www/index.php,header function does not work to jump to the index.php script file because it does not go through the server.

//index.phpheader("Location:demo.php");
//demo.phpecho "this is demo";

Request result diagram

Request graph received by the server

If you use curl, you need to turn on its redirect switch.

Curl can not use header

It is not possible to execute that php file directly in the code with the system invoke PHP command.

The first question, no,
Second, there will be no direct execution of the CLI with high performance

  • Related Article

    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.