0

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&param2=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

TwoDiv
  • 325
  • 4
  • 13
  • 1
    I've something you can think about - why use `file_get_contents` if all you need to do is "hit" the URL for everything to work? There's cURL, there's `header()`.. – Michael J.V. May 26 '11 at 13:11
  • Actually, the scripts stack also if I'm pasting all the url to the browser address bar, It's not the how I call it, its something else. The script runs but I'm getting "PHP Notice: Undefined index:" and it takes a lot of time – TwoDiv May 26 '11 at 13:19
  • Well, it was php mail problem, edited my post – TwoDiv May 26 '11 at 14:04

2 Answers2

0

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

Community
  • 1
  • 1
Jay Sidri
  • 6,271
  • 3
  • 43
  • 62
  • At least try to read, what is accepted answer for that question. URL length should not be limited, and 450 symbols it's ridiculous number for length limit. – OZ_ May 26 '11 at 13:24
0

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.

OZ_
  • 12,492
  • 7
  • 50
  • 68