NOVELTY - The method comprises: subjecting the wastewater containing incoming load of suspended solids (SS) to a primary treatment device (3); sending the sludge to a primary digester (5) for anaerobic production of biogas; carrying out biological treatment for wastewater; and varying the processing performance of the primary treatment for operating the digester with a digested slurry stream corresponding to the optimal load of the digester despite of variations in the incoming feed. The parameters of the primary treatment are set according to the incoming load of suspended solids.    USE - The method is useful for treating primary sludge municipal or industrial wastewater (claimed) for production of biogas that is recovered as electricity, heat, or used as a fuel.    ADVANTAGE - The method is capable of optimizing the operation of the digester to maximize energy, and optimizing the production of biogas from the digestion plant in operation.    DETAILED DESCRIPTION - The method comprises: subjecting the wastewater containing incoming load of suspended solids (SS) to a primary treatment device (3); sending the sludge to a primary digester (5) for anaerobic production of biogas; carrying out biological treatment for wastewater; and varying the processing performance of the primary treatment for operating the digester with a digested slurry stream corresponding to the optimal load of the digester despite of variations in the incoming feed. The parameters of the primary treatment are set according to the incoming load of suspended solids so as to increase production of primary sludge when the incoming load of wastewater to be treated is lower and to reduce the production of primary sludge when incoming load is higher, by which the digester operates at its optimum load despite of variations in pollution load input of a wastewater treatment plant. The speed of passage of sewage in the filtration is reduced when the pollution load is lower to increase the production primary sludge, during the primary filtration treatment. The primary filtration treatment is carried out by adding doses of flocculant and/or coagulant to the wastewater. The increase in production of primary sludge, in the primary treatment, is limited so as not to decrease the residence time in the digester below a critical value. The increased production of primary sludge is limited so as not to decrease the residence time in the digester of below 16 days, in the case of mesophilic digestion. An INDEPENDENT CLAIM is included for an installation for carrying out the method.    DESCRIPTION OF DRAWING(S) - The figure shows a block diagram of an installation for treating wastewater.    Primary treatment device (3)    Measuring device (4a)    Connecting member (4b)    Primary digester (5)    Suspended solids. (SS)