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 265929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:48:44+00:00 2026-05-11T22:48:44+00:00

I am trying to code a custom url_rewriter for squid. & also with using

  • 0

I am trying to code a custom url_rewriter for squid.
& also with using some other url_rewriter programs like squidGuard
so have to use a wrapper to able use both or any other program.

when i try to loop with php.
(that’s the way how squid communicates with external programs.
STDIN/STDOUT. it gives you a url & you have to send the new one or old one back. )

it has a devastating memory usage even doing nothing.
i’ve changed to wrap it with another bash script it is only a few lines.
& it loops instead of php. calls php externally. when php script is done with the url returns it & exits.
this way is much more better than instead of to loop the php script.

in php script nearly there is nothing now. (coz i’m still developing it.)
it’s only replacing video.yahoo.com to youtube.com.
and a few variable and an explode() to parse input string that’s all…
but script is still using huge amount of memory


here is the top output:

 PID USER   VIRT  RES  SHR S %CPU %MEM TIME+  COMMAND

32059 squid   19720 7432 4396 R    0.9    2.9    0:00.02   php      
32063 squid   19720 7436 4396 R    0.9    2.9    0:00.02   php      
32066 squid   19720 7436 4396 R    0.9    2.9    0:00.02   php      
32068 squid   19460 6188 3472 R    0.9    2.4    0:00.02   php      
32070 squid   19720 7432 4396 R    0.9    2.9    0:00.02   php      
32074 squid   19588 6792 3924 R    0.9    2.6    0:00.02   php      
32077 squid   19720 7436 4396 R    0.9    2.9    0:00.02   php   

here is the PHP script

#!/opt/lampp/bin/php -q 
<php
ini_set('html_errors',false);
ini_set('implicit_flush',true);
ini_set('max_execution_time',0);
ini_set('register_argc_argv',true);

$nl="\n"; $tab="\t";
$ds=DIRECTORY_SEPARATOR;
$lamppdir='/opt/lampp/';
$htdocsdir='/opt/lampp/htdocs/';
$wdir='/opt/lampp/htdocs/bin/';
$incdir=$htdocsdir.'inc/';
$logfile=$wdir.'log.txt';

if ($argc>1){
    $return=$argv[1];
    $return=explode(' ',trim($return));
    $url=$return[0];
    $sourceip=$return[1];
    $user=$return[2];
    $method=$return[3];
    $urlgroup=$return[4];
    $myip=$return[5];
    $myport=$return[6];

    $logdata=$argv[1];

    // if(strlen($logdata)>50){ file_put_contents($logfile,$logdata.$nl,FILE_APPEND); }

    fwrite(STDOUT,$return[0]."\r\n");
}

exit(0);

And here is the bash script

#!/bin/bash
 lamppdir=/opt/lampp/
 phpexecpath=/opt/lampp/bin/php
 phpredirectorpath=/opt/lampp/htdocs/bin/redir.php
 logdfile=/opt/lampp/htdocs/bin/log.txt
 forcedexit=false

 while [ "${forcedexit}" != "true" ]
 do
    read squidinput
    phpout=`"${phpexecpath}" "${phpredirectorpath}" "${squidinput}"`
    echo "${phpout}"
 done

 echo "\r\n"

exit 0

i already googled to find any useful documentation about PHP cli & source usage but no luck.

Do you have any advice to decrease source usage ?

  • 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-11T22:48:44+00:00Added an answer on May 11, 2026 at 10:48 pm

    i bet you will laugh at this. i was looking at the wrong place.

    after a long tracing stdin/stdout of squid.
    i’ve just added an if statement in the loop. to control string’s length as a url.

    while [ "${forcedexit}" != "true" ]
    do
        read squidinput
        if [ -n squidinput ]
           then
            phpout=`"${phpexecpath}" "${phpredirectorpath}" "${squidinput}"`
            echo "${phpout}"
        fi
    done
    

    result: there is no waiting php processes in background anymore.
    because it’s handling & exiting just in milliseconds.

    without the IF statement squid is sending empty spaces and newlines to script so it never stops. i was trimming input string with php that is why i couldn’t get earlier squid’s weird stdins. trimming $argv is just an habit brought.
    squid version was 2.6stable7 probably it’s all the same in earlier versions.
    i’ve just lost half a day 🙁
    thank you for everyone read.

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

Sidebar

Ask A Question

Stats

  • Questions 215k
  • Answers 215k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You have to get hold of the elements that are… May 12, 2026 at 10:52 pm
  • Editorial Team
    Editorial Team added an answer This sounds somewhat similar to the work by Simon Peyton… May 12, 2026 at 10:52 pm
  • Editorial Team
    Editorial Team added an answer Per this thread, R.styleable has been removed from android 1.5… May 12, 2026 at 10:52 pm

Related Questions

Server Details: FreeBSD PHP Version 4.3.11 Apache Appache Modules: mod_throttle, mod_php4, mod_speedycgi, mod_ssl, mod_setenvif,
hi i am trying to create a custom attribute for my MVC application so
I'am trying to develop a Custom drupal module which will read arguments from the
hi i am trying to create a URL that looks like this: black/granite/worktops where

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.