1. When writing a string to a file using the function file_put_contents, our team used various formats to define the target filename.
PHP
file_put_contents(Yii::$app->runtimePath . '/cmsTop.log', date('Y-m-d H:i:s') . ' '. $uri . ' ' . var_export($data, true), FILE_APPEND);
$bathPath = Yii::$app->getBasePath();
@file_put_contents($bathPath . '/runtime/responseResult.txt', var_export($url, true)."\n", LOCK_EX);
file_put_contents('/tmp/123', date('Y-m-d H:i:s') . ' bk_create_params' . var_export($data, 1) . PHP_EOL, FILE_APPEND);
file_put_contents('E:/wwwroot/channel-pub-api/console/runtime/upload-asset-image-exec-handler-' . $assetId . '-' . time() . '.txt', print_r($assetId, true));
2. The problem with these different formats is that as the program’s runtime environment changes, the filename for the written data also constantly changes. This leads to write failures, which could be due to path issues or permission issues. We ultimately decided to standardize on a single format: using Aliases to improve universality and the success rate.
PHP
file_put_contents(Yii::getAlias('@runtime') . '/qq-tp-transaction-video-sync-' . microtime(true) . '-' . mt_rand() . '.txt', print_r($qqTransactionServiceHttpTransactionInfoResult, true), FILE_APPEND | LOCK_EX);
3. The final written filename: /mcloud/www/channel-pub-api/console/runtime/qq-tp-transaction-video-sync-1596087411.7955-2004360950.txt. Its contents are as follows. See Figure 1.

Plaintext
Array
(
[transaction_id] => 781154629713605046
[transaction_status] => Success
[ext_err] => 0
[transaction_err_msg] =>
[transaction_type] => Article
[transaction_ctime] => 2020-07-24 16:32:22
[article_info] => Array
(
[article_title] => 追梦身影·西迁往事之峥嵘岁月
[article_type] => Video Article
[article_abstract] => 追梦身影·西迁往事之峥嵘岁月
[article_imgurl] => http://inews.gtimg.com/newsapp_ls/0/12144797745_196130/0
[article_pub_flag] => Published Successfully
[article_pub_time] => 2020-07-24 16:32:22
[article_id] => 20200724V0MC8V
[article_url] => http://kuaibao.qq.com/s/20200724V0MC8V00
[article_video_info] => Array
(
[vid] => e3121ha42ez
[title] => 追梦身影·西迁往事之峥嵘岁月
[duration] => 00:05:14
[desc] => 追梦身影·西迁往事之峥嵘岁月
[type] => video
)
[article_pid] =>
)
)
