php file_get_contents 和文件长度的问题

发布于 2024-11-09 17:37:01 字数 937 浏览 0 评论 0原文

我编写了一个简单的 api,将数据从一台服务器汇集到另一台服务器。它是一个非常简单的基于 $_GET 的 api,其中所有数据都作为 GET 数据附加到 url 中。

所以我得到类似的东西: http://example.com/api.php?param1=afdsa&param2=TTTT&....等。

为了调用它,我使用 file_get_contents($url); 首先 - 我真的不需要回复的内容。我只需要“触摸”该网址,它就会立即生效。

我的托管(共享、justhost)出现问题,我已转向 VPS。 我的 api 调用开始超时,当我检查 apache error.log 时,我看到:

"failed to open stream: File name too long in ..."

事实上 - $url 字符串大约有 450 个字符。

问题是 - 我在哪里更改文件长度的设置。它与硬盘驱动器文件系统不同,因为我自己的计算机得到相同的字符串,没有问题,也没有错误。 另外 - 共享主机对该网址没有任何问题。

VPS 运行 ubuntu 10.04 lts,PHP 版本 5.3.2-1ubuntu4.9

感谢任何帮助,已经坐了两天了

已解决

好吧,当您认为自己知道问题出在哪里时,您知道是怎么回事但事实并非如此?嗯——这就是问题所在。 我重写了我的 API,所以它要做的就是 print_r($_GET); 你知道吗 - 它工作得很好。 于是我开始一一添加这些行,发现堆叠脚本的是一个php邮件函数。为什么?我不知道,也许邮件设置不正确 - 但现在,当我注释掉邮件时 - 一切正常。

它仍然无法解释我的“文件太长”错误,但没关系。谢谢大家

I've wrote a simple api that bring together data from one server to the other. its a very simple $_GET based api where all the data is appended as GET data to the url.

So I get something like:
http://example.com/api.php?param1=afdsa¶m2=TTTT&....etc.

In order to call it I use file_get_contents($url);
first of all - I don't really need the content of the reply. I just need to "touch" the url so it will kick into action.

I had problems with my hosting (shared, justhost) and I've moved along to a VPS.
I've started to get timeout on my api calls and when I've checked the apache error.log I've saw:

"failed to open stream: File name too long in ..."

And indeed - the $url string is around 450 chars.

The question is - where do I change the setting for the file length. Its not the same as the Hard drive file system because my own computer get the same string with no problems and with no errors.
also - the shared hosting did not have any problems with that url.

The VPS runs ubuntu 10.04 lts with PHP Version 5.3.2-1ubuntu4.9

Appreciate any help, been sitting on that for two days

SOLVED

Well you know how is it when you think you know where the problem is but its not? well - that was the problem.
I've rewritten my API so all it will do is print_r($_GET); and what do you know - it worked fine.
So I've started to add the lines one by one and found out that what stacked the script was a php mail function. Why? I don't know, maybe mail setting are not correct - but now, when I've commented out the mailing - all works fine.

It still doesn't explain my "file to long" error, but never mind. Thanks to you all

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏夜暖风 2024-11-16 17:37:01

您的 URI 似乎太长。

相关:不同浏览器中 URL 的最大长度是多少?

考虑使用 CURL 将变量 POST 到 api.php

It looks like your URI is too long.

Relevant: What is the maximum length of a URL in different browsers?

Consider using CURL to POST your variables to api.php

野侃 2024-11-16 17:37:01

您的问题不在 file_get_contents 中,而是在 fopen 或其他尝试创建文件的函数中。它可以是缓存系统 - 不能说没有代码。
换句话说,问题不在于 url 的长度,而在于文件名的长度。
无法打开流 - 这是来自文件处理程序的错误消息。
URL长度不受限制,即使受到服务器(如apache)的限制,也不会被警告为错误。

Your problem not in file_get_contents, but in fopen or other function, which trying to create file. It can be caching system - can't say without code.
In other words, problem not in length of url - only in length of the name of file.
failed to open stream - it's error message from file handler.
Length of URL not limited, and even if limited by the server (e.g. apache), it will not be warned as error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文