In Yii 2.0, based on the function: file_put_contents, when writing a string to a file, use the alias ( aliases ) to improve the universality
1. Based on the function: file_put_contents, when a string is written to the file, there are various forms in the group when defining the file name to be written to
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. Under different forms, the problem is that with the change of the running environment of the program, the file name of the written data is also constantly changing. This leads to write failure. It may be a path problem, or it may be a permission problem. The final decision is unified as a form. Use aliases (aliases) to improve universality and success rates
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 file name written: /mcloud/www/channel-pub-api/console/runtime/qq -tp-transaction-video-sync-1596087411.7955-2004360950.txt. Its content is as follows. as shown in Figure 1
Array
(
[transaction_id] => 781154629713605046
[transaction_status] => 成功
[ext_err] => 0
[transaction_err_msg] =>
[transaction_type] => 文章
[transaction_ctime] => 2020-07-24 16:32:22
[article_info] => Array
(
[article_title] => 追梦身影·西迁往事之峥嵘岁月
[article_type] => 视频文章
[article_abstract] => 追梦身影·西迁往事之峥嵘岁月
[article_imgurl] => http://inews.gtimg.com/newsapp_ls/0/12144797745_196130/0
[article_pub_flag] => 发布成功
[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] =>
)
)
