No response is returned when executing the PDF creation API

When I run the DF creation API, no response is returned.
The error when executed is as follows.
It was running normally until around September 30, 2024.
It may be possible to execute the API once, but if you execute the API continuously, no response will be returned or it will be very slow.

[2024-10-06 13:27:10] local.ERROR: Server error: GET https://api.aspose.cloud/v3.0/cells/67020692228fa.xlsx?format=pdf&folder=tmp_files&region=Japan resulted in a 504 Gateway Time-out response:

504 Gateway Time-out

The server didn’t respond in time.

{“exception”:"[object] (GuzzleHttp\Exception\ServerException(code: 504): Server error: GET https://api.aspose.cloud/v3.0/cells/67020692228fa.xlsx?format=pdf&folder=tmp_files&region=Japan resulted in a 504 Gateway Time-out response:

504 Gateway Time-out

The server didn’t respond in time.

@banana0877
Please share your input document and code sample to reproduce the issue.

@kirill.novinskiy
Document is here.

code sample

<?php

class CreateCorporateRestorationReportFileForBanks implements ShouldQueue
{
    public function handle(
        RestorationReportFileService $restorationReportFileService,
        $arrays
    ): void
    {
        $arrays->map(function($bank) {

            $template = Storage::disk('local')->path("templates/restoration_reports/mr_corporation.xlsx");
            $excel = new ExcelWriter($template);
            $excel->save(Storage::path("uploaded_excel.xlsx"));

            if((isProduction() || isStaging())) {
                $api = new App\Utils\AsposeApi();
                $api->convertWorkbook("uploaded_excel.xlsx", "uploaded_excel.pdf", from_disk: 'efs', to_disk: 'efs', calculate_formulas: true);
            }
        });
    }
}
<?php

namespace App\Utils;

use Exception;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\Utils;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Symfony\Component\HttpFoundation\Response;

class AsposeApi
{
    private const BASE_URL = 'https://api.aspose.cloud';

    private readonly Client $client;

    private readonly string $aspose_client_id;

    private readonly string $aspose_client_secret;

    private readonly ?string $aspose_fonts_folder;

    private ?string $access_token = null;

    private int $tries = 3;

    private int $backoff = 60;

    public function __construct()
    {
        $this->aspose_client_id = env('ASPOSE_API_CLIENT_ID')
            ?? throw new Exception();
        $this->aspose_client_secret = env('ASPOSE_API_CLIENT_SECRET')
            ?? throw new Exception();
        $this->aspose_fonts_folder = env('ASPOSE_API_FONTS_FOLDER');

        $this->client = new Client([
            'base_uri' => self::BASE_URL,
            'headers' => [
                'User-Agent' => 'Aspose-Cells-Cloud-PHP/24.7/php',
            ],
        ]);
    }

    private function authenticate(int $attempt = 1): void
    {
        try {
            $response = $this->client->post(
                '/connect/token',
                [
                    'headers' => [
                        'Content-Type' => 'application/x-www-form-urlencoded',
                        'Accept' => 'application/json',
                    ],
                    'form_params' => [
                        'grant_type' => 'client_credentials',
                        'client_id' => $this->aspose_client_id,
                        'client_secret' => $this->aspose_client_secret,
                    ],
                ],
            );
        } catch(RequestException $ex) {
            $response = $ex->getResponse();
        }

        if($response->getStatusCode() === Response::HTTP_OK) {
            $this->access_token = json_decode($response->getBody()->getContents())->access_token;
        } else if(in_array($response->getStatusCode(), [Response::HTTP_UNAUTHORIZED, Response::HTTP_NOT_FOUND], true)) {
            throw new Exception();
        } else {
            if ($attempt >= $this->tries) {
                if(isset($ex)) {
                    throw $ex;
                }
                throw new Exception();
            } else {
                sleep($this->backoff);
                $this->authenticate($attempt + 1);
            }
        }
    }

    public function convertWorkbook(
        string $from_file_path,
        string $to_file_path,
        string $to_format = 'pdf',
        string $from_disk = 'local',
        string $to_disk = 'local',
        bool $calculate_formulas = false
    ): void {
        if ($calculate_formulas) {
            $this->calculateFormulasAndConvertWorkbook(
                $from_file_path,
                $to_file_path,
                $to_format,
                $from_disk,
                $to_disk
            );
        } else {
            $this->convertLocalWorkbook(
                $from_file_path,
                $to_file_path,
                $to_format,
                $from_disk,
                $to_disk
            );
        }
    }

    private function convertLocalWorkbook(
        string $from_file_path,
        string $to_file_path,
        string $to_format = 'pdf',
        string $from_disk = 'local',
        string $to_disk = 'local'
    ): void {
        if (! $this->access_token) {
            $this->authenticate();
        }

        $response = $this->client->put(
            '/v3.0/cells/convert',
            [
                'headers' => [
                    'Authorization' => 'Bearer '.$this->access_token,
                ],
                'sink' => Storage::disk($to_disk)->path($to_file_path),
                'query' => [
                    'format' => $to_format,
                    'region' => "Japan",
                    ...(
                        $this->aspose_fonts_folder
                        ? ['fontsFolder' => $this->aspose_fonts_folder]
                        : []
                    ),
                ],
                'multipart' => [[
                    'name' => 'file',
                    'contents' => Utils::tryFopen(
                        Storage::disk($from_disk)->path($from_file_path),
                        'rb'
                    ),
                ]],
            ]
        );

        if ($response->getStatusCode() !== 200) {
            throw new Exception();
        }
    }

    private function calculateFormulasAndConvertWorkbook(
        string $from_file_path,
        string $to_file_path,
        string $to_format = 'pdf',
        string $from_disk = 'local',
        string $to_disk = 'local'
    ): void {
        $remote_file_path = 'tmp_files/'.uniqid().'.xlsx';

        $this->uploadFile(
            $from_file_path,
            $remote_file_path,
            $from_disk
        );
        $this->calculateFormulas($remote_file_path);
        $this->convertRemoteWorkbook(
            $remote_file_path,
            $to_file_path,
            $to_format,
            $to_disk
        );
    }

    public function uploadFile(
        string $local_file_path,
        string $remote_file_path,
        string $local_disk = 'local',
        int $attempt = 1
    ): void {
        if (! $this->access_token) {
            $this->authenticate();
        }

        try {
            $response = $this->client->put(
                '/v3.0/cells/storage/file/'.$remote_file_path,
                [
                    'headers' => [
                        'Authorization' => 'Bearer '.$this->access_token,
                    ],
                    'multipart' => [[
                        'name' => 'file',
                        'contents' => Utils::tryFopen(
                            Storage::disk($local_disk)->path($local_file_path),
                            'rb'
                        ),
                    ]],
                ]
            );
        } catch(RequestException $ex) {
            $response = $ex->getResponse();
        }

        if($response->getStatusCode() === Response::HTTP_OK) {
            return;
        } else if(in_array($response->getStatusCode(), [Response::HTTP_UNAUTHORIZED, Response::HTTP_NOT_FOUND], true)) {
            throw new Exception();
        } else {
            if ($attempt >= $this->tries) {
                if(isset($ex)) {
                    throw $ex;
                }
                throw new Exception();
            } else {
                sleep($this->backoff);
                $this->uploadFile($local_file_path, $remote_file_path, $local_disk, $attempt + 1);
            }
        }

        if ($response->getStatusCode() !== 200) {
            throw new Exception();
        }
    }

    public function calculateFormulas(
        string $remote_file_path,
        int $attempt = 1
    ): void
    {
        if (! $this->access_token) {
            $this->authenticate();
        }

        $base_name = basename($remote_file_path);
        $dir_name = dirname($remote_file_path);

        try {
            $response = $this->client->post(
                '/v3.0/cells/'.$base_name.'/calculateformula',
                [
                    'headers' => [
                        'Authorization' => 'Bearer '.$this->access_token,
                    ],
                    'query' => [
                        ...($dir_name !== '.' ? ['folder' => $dir_name] : []),
                    ],
                    'json' => [
                        'name' => $remote_file_path,
                        'options' => [],
                    ],
                ]
            );
        } catch(RequestException $ex) {
            $response = $ex->getResponse();
        }

        if($response->getStatusCode() === Response::HTTP_OK) {
            return;
        } else if(in_array($response->getStatusCode(), [Response::HTTP_UNAUTHORIZED, Response::HTTP_NOT_FOUND], true)) {
            throw new Exception();
        } else {
            if ($attempt >= $this->tries) {
                if(isset($ex)) {
                    throw $ex;
                }
                throw new Exception();
            } else {
                sleep($this->backoff);
                $this->calculateFormulas($remote_file_path, $attempt + 1);
            }
        }
    }

    public function convertRemoteWorkbook(
        string $remote_file_path,
        string $to_file_path,
        string $to_format = 'pdf',
        string $to_disk = 'local',
        int $attempt = 1
    ): void {
        if (! $this->access_token) {
            $this->authenticate();
        }

        $base_name = basename($remote_file_path);
        $dir_name = dirname($remote_file_path);

        try {
            $response = $this->client->get(
                '/v3.0/cells/'.$base_name,
                [
                    'headers' => [
                        'Authorization' => 'Bearer '.$this->access_token,
                    ],
                    'sink' => Storage::disk($to_disk)->path($to_file_path),
                    'query' => [
                        'format' => $to_format,
                        'folder' => $dir_name,
                        'region' => "Japan",
                        ...(
                            $this->aspose_fonts_folder
                            ? ['fontsFolder' => $this->aspose_fonts_folder]
                            : []
                        ),
                    ],
                ]
            );
        } catch(RequestException $ex) {
            $response = $ex->getResponse();
        }

        if($response->getStatusCode() === Response::HTTP_OK) {
            return;
        } else if(in_array($response->getStatusCode(), [Response::HTTP_UNAUTHORIZED, Response::HTTP_NOT_FOUND], true)) {
            throw new Exception();
        } else {
            if ($attempt >= $this->tries) {
                if(isset($ex)) {
                    throw $ex;
                }
                throw new Exception();
            } else {
                sleep($this->backoff);
                $this->convertRemoteWorkbook($remote_file_path, $to_file_path, $to_format, $to_disk, $attempt + 1);
            }
        }
    }
}

@banana0877 Further testing is needed to find out the cause of this problem. Please provide your cloud registration email address for troubleshooting.

@xuejianzhang emailaddress:taro.kimura@sinka-inc.com,pf@sinka-inc.com

@banana0877 we will check this out asap.

@xuejianzhang Hi. How is the situation?

@banana0877 we are still working with other departments to further determine the cause of the problem. I would like to ask if this situation still occurs?

@xuejianzhang
I’ll run it tonight and check.

@banana0877 Thank you for the information, we are continuing to investigate all possibilities that may be causing this issue.

@xuejianzhang
Please continue your investigation.
One more thing. What is the problem with the font in the Excel graph changing when it is in PDF?
excel_graph.png (36.6 KB)

pdf_graph.png (75.2 KB)

@banana0877 Hello, please provide us with your test files and code examples so that we can reproduce this problem. What font do you use in the Excel chart where the problem occurs?

@xuejianzhang
Code and sample files were answered 6 days ago.
The font is Meiryo(メイリオ).

@banana0877
We have reproduced the font abnormality problem and have opened the following new ticket(s) in our internal issue tracking system.

Issue ID(s): CELLSCLOUD-12976

We are working on a solution to this problem and will let you know as soon as we have any progress.

@banana0877
We have made some improvements, please take a look at the results of this conversion to see if you like it.
simple.pdf (307.9 KB)

@xuejianzhang Looks like it’s okay. Do I need to change anything here?

@banana0877 You don’t need to modify anything. We will update this content in the next version after confirming that it is correct.

@xuejianzhang thank you! When will the version be updated?

@banana0877 We will notify you as soon as it is released.

@banana0877 We have updated the version and tested and fixed this problem. You can try it.