为什么即使磁盘已满,PHP也会返回0

时间:2019-03-30 19:04:19

标签: php exit-code

我将php进程(cli模式)的标准输出重定向到文件。

为什么磁盘已满时退出代码为0。

我可以在php 7.1 / 5.6 / 5.4中以及macos和centos中再次出现此问题。

TypeError: "o is undefined"

以下是 data: () => { return { items_data: [], fields: [ {key: this.$i18n.t('next')}, //<-- Translate table header values {key: 'name'}, {key: 'registered'}, {key: 'role'}, {key: 'status'} ], currentPage: 1, perPage: 5, totalRows: 0 } 的内容:

<template>
  <b-row>
    <b-col cols="12" xl="6">
      <transition name="slide">
      <b-card :header="caption">
        <b-table :hover="hover" :striped="striped" :bordered="bordered" :small="small" :fixed="fixed" responsive="sm" :items="items" :fields="fields" :current-page="currentPage" :per-page="perPage" @row-clicked="rowClicked">
          <template slot="id" slot-scope="data">
            <strong>{{data.item.id}}</strong>
          </template>
          <template slot="name" slot-scope="data">
            <strong>{{data.item.name}}</strong>
          </template>
          <template slot="status" slot-scope="data">
            <b-badge :variant="getBadge(data.item.status)">{{data.item.status}}</b-badge>
          </template>
        </b-table>
        <nav>
          <b-pagination size="sm" :total-rows="5" :per-page="perPage" v-model="currentPage" :prev-text="$t('previous')" :next-text="$t('next')" hide-goto-end-buttons/>
        </nav>
      </b-card>
      </transition>
    </b-col>
  </b-row>
</template>

<script>
var usersData = null;
export default {

  name: 'Test Users',
  props: {
    caption: {
      type: String,
      default: 'Users 2'
    },
    hover: {
      type: Boolean,
      default: true
    },
    striped: {
      type: Boolean,
      default: true
    },
    bordered: {
      type: Boolean,
      default: false
    },
    small: {
      type: Boolean,
      default: false
    },
    fixed: {
      type: Boolean,
      default: false
    }
  },
  data: () => {
    return {
      items_data: [],
      fields: [
        {key: this.$i18n.t('next')}, //<-- Translate table header values
        {key: 'name'},
        {key: 'registered'},
        {key: 'role'},
        {key: 'status'}
      ],
      currentPage: 1,
      perPage: 5,
      totalRows: 0
    }
  },
  mounted() {
    this.axios.getAll()
      .then(response => {
        //this.$log.debug("Data loaded: ", response.data) 
        this.items_data = response.data
      }).catch(error => {  
      //this.$log.debug(error)  
      this.error = "Failed to load todos"  
    }) 
  },
  computed: {
    items: function () { 
      return this.items_data;
    }
  },
  methods: {
    getBadge (status) {
      return status === 'Active' ? 'success'
        : status === 'Inactive' ? 'secondary'
          : status === 'Pending' ? 'warning'
            : status === 'Banned' ? 'danger' : 'primary'
    },
    getRowCount (items) {
      return items.length
    },
    userLink (id) {
      return `users/${id.toString()}`
    },
    rowClicked (item) {
      const userLink = this.userLink(item.id)
      this.$router.push({path: userLink})
    }

  }
}
</script>

<style scoped>
.card-body >>> table > tbody > tr > td {
  cursor: pointer;
}
</style>

当我使用python时,它按预期以1退出。

leojins-MacBook-Pro-2:Downloads leojin$ php test.php > /Volumes/disk_test/test.log
leojins-MacBook-Pro-2:Downloads leojin$ echo $?
0
leojins-MacBook-Pro-2:Downloads leojin$ df -h
Filesystem      Size   Used  Avail Capacity iused               ifree %iused  Mounted on
/dev/disk1s1   233Gi   27Gi  205Gi    12%  580000 9223372036854195807    0%   /
devfs          189Ki  189Ki    0Bi   100%     654                   0  100%   /dev
/dev/disk1s4   233Gi  1.0Gi  205Gi     1%       1 9223372036854775806    0%   /private/var/vm
map -hosts       0Bi    0Bi    0Bi   100%       0                   0  100%   /net
map auto_home    0Bi    0Bi    0Bi   100%       0                   0  100%   /home
/dev/disk2s1    95Mi   93Mi  1.5Mi    99%      96 9223372036854775711    0%   /Volumes/disk_test

以下是test.php的内容:

<?php
$i = 0;
while (true) {
    echo "php:" . $i . "\n";
    $i++;
}

我也尝试过leojins-MacBook-Pro-2:Downloads leojin$ python test.py > /Volumes/disk_test/test.log Traceback (most recent call last): File "test.py", line 3, in <module> print 'python:' + str(i) IOError: [Errno 28] No space left on device leojins-MacBook-Pro-2:Downloads leojin$ echo $? 1 test.py,没有区别。

1 个答案:

答案 0 :(得分:1)

您的PHP代码不会写入磁盘,您也setting an exit status不在代码中的任何位置。因此,没有理由异常退出。如果要检查磁盘是否已满,建议您执行in your shellin PHP

我不太熟悉它,但是我猜您的Python解释器可能会抛出此错误,因为代码在执行前是compiled to bytecode。如果没有空间,那么它将无法执行此中间步骤。

相关问题