PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I've the need to capture a php script's output into a variable. Using shell_exec() or other system functions isn't an option to me, although shell_exec() is the behavior I'm after.
I was told to use file_get_contents() or fsockopen() to initiate a separate HTTP request. I've played around with fsockopen() for quite a bit now, and can't seem to get it.
Only, not have the php code returned, but the php code to be executed and the result returned.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
You have to actually make it an HTTP request to do it with file_get_contents(); http:// and all.
You're basically doing an ob_start()+include()+ob_get_clean()... but since this is likely apart of your cron solution won't shunt to a separate thread/process.
@feyd, yes, you're right. I'm thinking I stand better to do the ob_start(), include, ob_get_clean(), since many shared server configurations are very nitpicky about what they let you use with system calls and file calls (found this out today).
I wouldn't imagine they'd have much control over ob_* and include.
I'm not worrying about forking the process right now, just trying to get what I have working.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Is there a way to not have php save the variables with the include() call, but disregard them?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
The other thing to worry about is possible collisions that may occur as a result of including these files.. specifically redefinition of functions and classes. Provided they are engineered carefully, you won't run into problems, but it's quite possible to hit errors in many cases. That's why file_get_contents() and fsockopen() are generally better solutions.
file_get_contents() would require me knowing the domain, and as aborint said, server configuration
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
That's all possible to determine via $_SERVER and some logic. The only problem is it has to be accessible via a HTTP request. Granted, an .htaccess could limit the exposure that would have to only accept requests from the server itself...
Looks like allow_url_fopen is off in the one shared hosting server I tested. Looks like I'll be going the include() route.
My only concern is memory hogging in an infite loop. Granted, the same variables will be overwritten, when necessary, but they will never be discarded from memory either.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.