dream07769 2019-01-07 08:56
浏览 61

如何在php中调用当前文件?

in my code, I am making curl call and after getting response I am calling current file if proper response does not get. like this,

<?php
include 'fauxapi_client.php';
$obj = new Fauxapi_client;

$url=$obj->base_url.'/Fauxapi_client/device_version_update';
$version = trim(file_get_contents('/usr/local/www/version.txt'));
$iso_version = trim(file_get_contents('/usr/local/www/iso_version.txt'));
$temp = array('device_ip'=>$obj->current_device_ip,'version'=>$version,'iso_version'=>$iso_version);
$temp = http_build_query($temp);
$headers[] = 'Content-Type: application/x-www-form-urlencoded; charset=utf-8';
$ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0); 
curl_setopt($ch, CURLOPT_TIMEOUT, 40);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $temp);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
$output = curl_exec ($ch);
curl_close ($ch);
if ($output === false) {
    echo 'Curl Call Fail';
}
else{
    $response = json_decode($output,true);
    if (isset($response['data']['next_version'])) {
        file_put_contents('/usr/local/www/version.txt', trim($response['data']['next_version']));
        if (floatval($response['data']['max_updatable_version']) > floatval($response['data']['next_version'])) {
            shell_exec("/usr/local/bin/php /usr/local/www/version_update.php");
        }
    }
    else{
        echo 'next_version is not in response ';
    }
}
var_dump($output);
?>

in the above code

shell_exec("/usr/local/bin/php /usr/local/www/version_update.php"); 

is a current file call. when I echo something there it will echo but not calling a current file. so, how to call current file there?

  • 写回答

1条回答 默认 最新

  • dox90448 2019-01-07 09:25
    关注

    Are you sure the extra space after php? bin/php / And if /usr/local/bin/php /usr/local/www/version_update.php is current file you can use __FILE__ instead it. And please make sure sufficient permissions.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度