简体   繁体   English

使用api时独立打开来自其他php文件的php文件

[英]Open php file from different php file independently while working with api

Ok so i have a script with 2 different API. 好的,所以我有一个具有2个不同API的脚本。

I have a file let call it paypal.php, that file work with paypal api. 我有一个名为paypal.php的文件,该文件可与paypal api一起使用。

When someone place an order on my website and pay with paypal the file paypal.php running and sending my email with the info about the order. 当有人在我的网站上下订单并使用Paypal付款时,文件paypal.php运行并发送有关该订单信息的电子邮件。 Now after sending the email the paypal.php open different file that work with different API that create invoices. 现在,在发送电子邮件之后,paypal.php打开另一个文件,该文件可与创建发票的不同API一起使用。

I am using the file_get_contents commend to open the other php 我正在使用file_get_contents推荐来打开其他PHP

file_get_contents($page_url, false);

on the file that is getting opened while using file_get_contents i am transferring data to the invoice website api. 在使用file_get_contents时正在打开的文件上,我正在将数据传输到发票网站api。 And then i wait 60 second and i am using sleep() function to do that. 然后我等待60秒钟,然后我使用sleep()函数来做到这一点。 After the 60 second are pass i download the invoices. 60秒过后,我下载了发票。

Now here my problem, the first file paypal.php seems to wait the 60 second as well. 现在这是我的问题,第一个文件paypal.php似乎也要等待60秒。 Because of the wait paypal API seems to think the server didn't respond and it running the api again and causing me problems like sending the same email twice and creating the invoice twice. 由于等待,PayPal API似乎认为服务器没有响应,因此它再次运行api,并给我造成了一些问题,例如发送相同的电子邮件两次和两次创建发票。

What i want to do is to open the invoice api independently without harming the paypal.php file. 我想要做的是独立打开发票api,而不会损害paypal.php文件。

I have tried few things without success. 我尝试了几件事却没有成功。 First i have tried to use this code while using sleep 首先,我尝试在使用睡眠时使用此代码

ob_flush();

flush();

sleep(60);

And it didn't worked out. 而且没有解决。 I have also tried to run this commend before loading the other file, to try and say to the API is was successful but it didn't work out as well. 我还尝试在加载另一个文件之前运行此命令,以尝试对API进行说明是成功的,但效果不佳。

header( "HTTP/1.1 200 OK" );

before loading the invoice file but it didn't worked out as well. 在加载发票文件之前,但效果不佳。

I have ended up changing the sleep commend to 10 second instead of 60 and that seems to work fine but i rather have it as 60 second to be on the safe side. 我最终将睡眠时间更改为10秒而不是60秒,这似乎很好,但是我宁愿将它设置为60秒也可以保证安全。

Does anyone have an idea what can i do to make it work? 有谁知道如何使它起作用? is there a way to load the invoice file independently without effecting the paypal.php? 有没有办法在不影响paypal.php的情况下独立加载发票文件?

If the file exists on your server, than you can use an include() statement to run the code in your invoice file. 如果文件存在于服务器上,则可以使用include()语句在发票文件中运行代码。 Just add: 只需添加:

include('/path/to/your/invoice/file');

Wherever you need it to start running. 无论您需要它在哪里开始运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM