From 2e0c1e3291682ae607a2ff240f270bfbb5467bb8 Mon Sep 17 00:00:00 2001 From: Angel Alonso Date: Mon, 18 Mar 2024 15:01:49 +0100 Subject: [PATCH 1/6] Test larger timeout for get_file operations --- files/class-api-client.php | 1 + 1 file changed, 1 insertion(+) diff --git a/files/class-api-client.php b/files/class-api-client.php index ca617d710b..50a9ddbe2d 100644 --- a/files/class-api-client.php +++ b/files/class-api-client.php @@ -205,6 +205,7 @@ public function get_file( $file_path ) { $request_args = [ 'stream' => true, 'filename' => $tmp_file, + 'timeout' => 60, ]; // not in cache so get from API From e9f93b7564bb5c131a3ac29e9e4ac54a4ab2ec00 Mon Sep 17 00:00:00 2001 From: Angel Alonso Date: Mon, 18 Mar 2024 17:21:50 +0100 Subject: [PATCH 2/6] 280s timeout for testing --- files/class-api-client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/class-api-client.php b/files/class-api-client.php index 50a9ddbe2d..c76707f5d1 100644 --- a/files/class-api-client.php +++ b/files/class-api-client.php @@ -205,7 +205,7 @@ public function get_file( $file_path ) { $request_args = [ 'stream' => true, 'filename' => $tmp_file, - 'timeout' => 60, + 'timeout' => 280, ]; // not in cache so get from API From f55c8c8b2efa0ffdc21e5dfbced676c2fd8240ef Mon Sep 17 00:00:00 2001 From: Angel Alonso Date: Fri, 22 Mar 2024 16:57:21 +0100 Subject: [PATCH 3/6] Try to get filesize from WP attachment meta --- files/class-vip-filesystem-stream-wrapper.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/files/class-vip-filesystem-stream-wrapper.php b/files/class-vip-filesystem-stream-wrapper.php index e11d4cef1e..3a6b6360ef 100644 --- a/files/class-vip-filesystem-stream-wrapper.php +++ b/files/class-vip-filesystem-stream-wrapper.php @@ -183,6 +183,14 @@ public function stream_open( $path, $mode, $options ) { } try { + // Get the post_id from the file path + $file_post_id = wpcom_vip_attachment_url_to_postid( $path ); + + // Get attachment metadata from $file_post_id + $attachment_metadata = wp_get_attachment_metadata( $file_post_id ); + $file_size = $attachment_metadata["filesize"]; + $this->debug( sprintf( 'filesize %s', $file_size ) ); + $result = $this->client->get_file( $path ); if ( is_wp_error( $result ) ) { From 7a8375db47519f63553704c26a85104e24d7547e Mon Sep 17 00:00:00 2001 From: Angel Alonso Date: Wed, 8 May 2024 11:53:27 +0200 Subject: [PATCH 4/6] Dynamically calculate get_file timeout --- files/class-api-client.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/files/class-api-client.php b/files/class-api-client.php index c76707f5d1..392e8b43e1 100644 --- a/files/class-api-client.php +++ b/files/class-api-client.php @@ -199,13 +199,21 @@ public function get_file( $file_path ) { return $file; } + // calculate timeout + $info = array(); + $this->is_file( $file_path, $info); + if ( is_wp_error( $info ) ) { + return $info; + } + + $request_timeout = $this->calculate_upload_timeout( $info['size'] ); $tmp_file = $this->cache->create_tmp_file(); // Request args for wp_remote_request() $request_args = [ 'stream' => true, 'filename' => $tmp_file, - 'timeout' => 280, + 'timeout' => $request_timeout, ]; // not in cache so get from API From fda0b867b3a7ea1d35c03912642478a4843f2aad Mon Sep 17 00:00:00 2001 From: Angel Alonso Date: Wed, 8 May 2024 12:38:52 +0200 Subject: [PATCH 5/6] Remove debug code --- files/class-vip-filesystem-stream-wrapper.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/files/class-vip-filesystem-stream-wrapper.php b/files/class-vip-filesystem-stream-wrapper.php index 3a6b6360ef..e11d4cef1e 100644 --- a/files/class-vip-filesystem-stream-wrapper.php +++ b/files/class-vip-filesystem-stream-wrapper.php @@ -183,14 +183,6 @@ public function stream_open( $path, $mode, $options ) { } try { - // Get the post_id from the file path - $file_post_id = wpcom_vip_attachment_url_to_postid( $path ); - - // Get attachment metadata from $file_post_id - $attachment_metadata = wp_get_attachment_metadata( $file_post_id ); - $file_size = $attachment_metadata["filesize"]; - $this->debug( sprintf( 'filesize %s', $file_size ) ); - $result = $this->client->get_file( $path ); if ( is_wp_error( $result ) ) { From 33ec8f787764f2bedc46aa99f75b04010432a0f1 Mon Sep 17 00:00:00 2001 From: Angel Alonso Date: Wed, 8 May 2024 12:40:44 +0200 Subject: [PATCH 6/6] Code style --- files/class-api-client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/class-api-client.php b/files/class-api-client.php index 392e8b43e1..b22eab1f62 100644 --- a/files/class-api-client.php +++ b/files/class-api-client.php @@ -201,7 +201,7 @@ public function get_file( $file_path ) { // calculate timeout $info = array(); - $this->is_file( $file_path, $info); + $this->is_file( $file_path, $info ); if ( is_wp_error( $info ) ) { return $info; }