file_get_contents errors help !

Discussion in 'PHP' started by technojuice, Aug 7, 2008.

  1. #1
    In a new server i am getting errors with my code which worked fine in localhost !

    Warning: file_get_contents() [function.file-get-contents]: Timeout was reached in /home/zook/public_html/crawl.php on line 17

    Warning: file_get_contents(http://google.com) [function.file-get-contents]: failed to open stream: Invalid argument in /home/zook/public_html/crawl.php on line 17

    I've tried increasing the :-

    ini_set('max_input_time',60);
    set_time_limit (300000);

    PHP VER - 5.2.6

    Any help appreciated !
     
    technojuice, Aug 7, 2008 IP
  2. Trusted Writer

    Trusted Writer Banned

    Messages:
    1,370
    Likes Received:
    52
    Best Answers:
    0
    Trophy Points:
    160
    #2
    Your output file might need chmod set to either 666 or 777, otherwise your new hosting can be prefenting the fopen function.
     
    Trusted Writer, Aug 7, 2008 IP
  3. technojuice

    technojuice Peon

    Messages:
    207
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    allow_url_fopen is ON !
     
    technojuice, Aug 7, 2008 IP
  4. jpinheiro

    jpinheiro Peon

    Messages:
    1,211
    Likes Received:
    15
    Best Answers:
    1
    Trophy Points:
    0
    #4
    did you try chmod the file to 0777
     
    jpinheiro, Aug 7, 2008 IP
  5. mallorcahp

    mallorcahp Peon

    Messages:
    141
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    from the error it looks like you might be doing:

    $myvar = file_get_contents(http://google.com);

    instead of this:

    $myvar = file_get_contents("http://google.com");

    ... maybe !?!
     
    mallorcahp, Aug 8, 2008 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    ^ That would have caused a parse error. He just copied the error message that PHP showed, and this doesn't include quotes.

    Neither max_input_time nor the time_limit affect file_get_contents()'s timeout. Try this instead:
    
    ini_set('default_socket_timeout', 120);
    
    PHP:
     
    nico_swd, Aug 8, 2008 IP
  7. guzz

    guzz Guest

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    why you use;
    set_time_limit (300000); ???

    you may simply ignore it by;
    set_time_limit (0);

    also fot your problem
    ini_set("default_socket_timeout", 240); //in my tests 240 is enought for reading ~300mb file with 1mbit connection.
     
    guzz, Aug 8, 2008 IP
  8. Property_Control

    Property_Control Peon

    Messages:
    18
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Show us the offending line, i'm sure i can help with this.
    But if you want a PHP Wrapper, which supports cookies, my friend wrote one
    You can find it at rcadble.net
     
    Property_Control, Aug 8, 2008 IP
  9. is0is0

    is0is0 Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Try doing:
    set_time_limit(0);
    ignore_user_abort(TRUE);
     
    is0is0, Aug 8, 2008 IP
  10. technojuice

    technojuice Peon

    Messages:
    207
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Nothing worked, i get the error where ever i use file_get_contents() here is the code is used:-
    <?php
    $url = "http://google.com";
    $html = file_get_contents($url);
    echo $html;
    ?>

    In the info page

    Configuration
    PHP Core
    Directive Local Value Master Value
    allow_call_time_pass_reference On On
    allow_url_fopen On On
    allow_url_include Off Off
    always_populate_raw_post_data Off Off
    arg_separator.input & &
    arg_separator.output & &
    asp_tags Off Off
    auto_append_file no value no value
    auto_globals_jit On On
    auto_prepend_file no value no value
    browscap no value no value
    default_charset no value no value
    default_mimetype text/html text/html
    define_syslog_variables Off Off
    detect_unicode On On
    disable_classes no value no value
    disable_functions no value no value
    display_errors STDOUT STDOUT
    display_startup_errors Off Off
    doc_root no value no value
    docref_ext no value no value
    docref_root no value no value
    enable_dl On On
    error_append_string no value no value
    error_log error_log error_log
    error_prepend_string no value no value
    error_reporting 6135 6135
    expose_php On On
    extension_dir /usr/local/lib/php/extensions/no-debug-non-zts-20060613 /usr/local/lib/php/extensions/no-debug-non-zts-20060613
    file_uploads On On
    highlight.bg #FFFFFF #FFFFFF
    highlight.comment #FF8000 #FF8000
    highlight.default #0000BB #0000BB
    highlight.html #000000 #000000
    highlight.keyword #007700 #007700
    highlight.string #DD0000 #DD0000
    html_errors On On
    ignore_repeated_errors Off Off
    ignore_repeated_source Off Off
    ignore_user_abort Off Off
    implicit_flush Off Off
    include_path .:/usr/lib/php:/usr/local/lib/php .:/usr/lib/php:/usr/local/lib/php
    log_errors On On
    log_errors_max_len 1024 1024
    magic_quotes_gpc On On
    magic_quotes_runtime Off Off
    magic_quotes_sybase Off Off
    mail.force_extra_parameters no value no value
    max_execution_time 30 30
    max_input_nesting_level 64 64
    max_input_time -1 -1
    memory_limit 8M 8M
    open_basedir no value no value
    output_buffering no value no value
    output_handler no value no value
    post_max_size 55M 55M
    precision 14 14
    realpath_cache_size 16K 16K
    realpath_cache_ttl 120 120
    register_argc_argv On On
    register_globals On On
    register_long_arrays On On
    report_memleaks On On
    report_zend_debug On On
    safe_mode Off Off
    safe_mode_exec_dir no value no value
    safe_mode_gid Off Off
    safe_mode_include_dir no value no value
    sendmail_from no value no value
    sendmail_path /usr/sbin/sendmail -t -i /usr/sbin/sendmail -t -i
    serialize_precision 100 100
    short_open_tag On On
    SMTP localhost localhost
    smtp_port 25 25
    sql.safe_mode Off Off
    track_errors Off Off
    unserialize_callback_func no value no value
    upload_max_filesize 2M 2M
    upload_tmp_dir no value no value
    user_dir no value no value
    variables_order EGPCS EGPCS
    xmlrpc_error_number 0 0
    xmlrpc_errors Off Off
    y2k_compliance Off Off
    zend.ze1_compatibility_mode Off Off
     
    technojuice, Aug 9, 2008 IP
  11. payu

    payu Peon

    Messages:
    40
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #11
    everything seems to be fine ... i guess, this leads us to only problem which is the host. they don't allow you to access outside web, maybe their firewall setting. you should contact your host support.

    another possibility is that your host and the web that you try to access has very poor connection which is not likely. contact support anyway.
     
    payu, Aug 10, 2008 IP