1、基于函数:file_put_contents,将一个字符串写入文件时,小组内部,在定义要被写入数据的文件名时有各种形式
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、在不同的形式下,存在的问题便是,随着程序运行环境的变化,写入数据的文件名也在在不断变化的。进而导致写入失败。可能是路径问题,也有可能是权限问题。最终决定统一为一种形式。使用 别名 ( Aliases ) 来提升普适性与成功率
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、最终写入的文件名:/mcloud/www/channel-pub-api/console/runtime/qq-tp-transaction-video-sync-1596087411.7955-2004360950.txt。其内容如下。如图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] =>
)
)
原创文章,作者:3628473679,如若转载,请注明出处:https://blog.ytso.com/tech/webdev/181543.html
