Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6323859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:35:56+00:00 2026-05-24T16:35:56+00:00

I’m working with a class that makes a remote connection to a server. A

  • 0

I’m working with a class that makes a remote connection to a server. A problem that I’m running into is if the connection doesn’t get a response, it’ll wait until it does.

This class does not have a timeout built into it, and I don’t want to modify it if I can avoid it.

Is there any way that I can wrap a section of code in something like this?

try(timeout seconds){
}catch(){
    //exception handle
}timeout(){
    // timeout handline
}

EDIT: I use the remote connection as one problem. I have others that I need to solve with this as well, like making system calls with exec or other similar things.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:35:57+00:00Added an answer on May 24, 2026 at 4:35 pm

    Not for only a section of the code.

    There is however alternative solutions, without modifying the original code, as requested:

    set_time_limit

    set_time_limit() will abort the whole script if it runs for too many time. You could still setup a shutdown function.

    pcntl_alarm

    pcntl_alarm() will send you a signal after a given amount of time, which may abort the blocking syscall the class is doing at that time, and this may allow you to ask the class to abort its operations if it provides such method. This may not be suitable in a web server environment, though.

    Default timeouts

    If the class is using stream functions, you may be able to set a default timeout:

    ini_set('default_socket_timeout', 5);
    stream_context_set_default(array(
        'http' => array(
            'timeout' => 5, 
        ),
    ));
    

    Execute in a separate process

    You could fork with pcntl_fork(), but this is not suitable in a server environment.

    You could also use proc_open or popen to execute a PHP script in a separate process and kill it if it runs for a too long time. (After the process is spawned, do an idle wait on the process’ stdout stream with stream_select.)

    Or setup a server for handling these tasks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.